package com.scalar.chiptrack.operations.reports.actions;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.RichTextString;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.util.CellRangeAddress;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.scalar.ScalarException;
import com.scalar.chiptrack.ChipTrackExtendedAction;
import com.scalar.chiptrack.calendar.Period;
import com.scalar.chiptrack.calendar.dao.CalendarDAO;
import com.scalar.chiptrack.marketing.dao.ForecastDAO;
import com.scalar.chiptrack.operations.process.dao.NewProductDAO;
import com.scalar.chiptrack.operations.reports.WaferStartData;
import com.scalar.chiptrack.operations.reports.dao.DataDumpReportsDAO;
import com.scalar.chiptrack.operations.reports.forms.WaferStartReportForm;
import com.scalar.chiptrack.utils.DateUtil;
import com.scalar.chiptrack.utils.ExcelUtils;
import com.scalar.chiptrack.utils.StringUtils;
import com.scalar.chiptrack.utils.ConfigManager;


/**
 * User: Sujan
 * Date: Jan 23, 2008
 * Time: 6:30:28 PM
 */
public class WaferStartReportAction extends ChipTrackExtendedAction
{
    Map<String, ArrayList<Range>> mergeIdxMap = new HashMap<String, ArrayList<Range>>();
    static FormulaEvaluator evaluator = null;
    
    public ActionForward executeRequest(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
    {
        HashMap<String, String> errors  = ( HashMap<String, String> ) request.getAttribute( ERROR_MESSAGES );
        HashMap<String, String> info    = ( HashMap<String, String> ) request.getAttribute( INFO_MESSAGES );
        String action   = request.getParameter( REQUEST_ACTION );
        WaferStartReportForm waferStartReportForm = (WaferStartReportForm)form;
        if ( action == null || action.trim().length() == 0 )
        {
            action = "search";
        }

        if ( "search".equalsIgnoreCase( action ) )
        {
            request.setAttribute( "fabPartNumbers", NewProductDAO.loadPartNumbers( null, 1, "FAB", true, true, true, 0 ) );
            return mapping.findForward( "search" );
        } else if ( "assemblyStartReportSearch".equalsIgnoreCase( action ) ) {
            request.setAttribute( "fabPartNumbers", NewProductDAO.loadPartNumbers( null, 1, "FAB", true, true, true, 0 ) );
            return mapping.findForward( "assemblyStartReportSearch" );
        }
       else if ( "generateReportXLS".equalsIgnoreCase( action ) )
        {
            Workbook workbook = null;

            //ArrayList<WaferStartData> waferStartDataList = DataDumpReportsDAO.getWaferStartReportWorkbookIkanos( waferStartReportForm.getFabProcessStepId() );
            ArrayList<WaferStartData> waferStartDataList = DataDumpReportsDAO.getWaferStartReportNew( waferStartReportForm.getFabProcessStepId() );
            String fctframe = ForecastDAO.getForecastTimeFrame(null);
            workbook = getWorkbookForBuildForecastReport ( waferStartDataList, "Wafer Start Reprot", fctframe );
            //workbook = DataDumpReportsDAO.getWaferStartReportWorkbook( null,  waferStartReportForm.getFabProcessStepId() );
            String fileName = "WaferStartReport_" + DateUtil.getTimeStamp();

            ExcelUtils.generateExcelReport( workbook, fileName, response);
        }
        else if ( "generateAssyStartReport".equalsIgnoreCase( action ) )
        {
            Workbook workbook = null;

            ArrayList<WaferStartData> waferStartDataList = DataDumpReportsDAO.getWaferStartReportNew( waferStartReportForm.getFabProcessStepId() );
            String fctframe = ForecastDAO.getForecastTimeFrame(null);
            workbook = getWorkbookForAssyStartReport ( waferStartDataList, "Assy Start Reprot", fctframe, waferStartReportForm.getReportType() );
            //workbook = DataDumpReportsDAO.getWaferStartReportWorkbook( null,  waferStartReportForm.getFabProcessStepId() );
            String fileName = "AssyStartReport_" + DateUtil.getTimeStamp();

            ExcelUtils.generateExcelReport( workbook, fileName, response);
        }

        return null;
    }
    
    public  Workbook getWorkbookForBuildForecastReport (ArrayList<WaferStartData> waferStartDataList, String ReportName, String fctframe ) throws ScalarException
    {
        Workbook workbook   = null;
        Sheet sheet       = null;
        if ( "xlsx".equalsIgnoreCase(ConfigManager.getXLSWorkBookFormat() ) )
        {
            workbook    = new XSSFWorkbook();
        }
        else
        {
            workbook    = new HSSFWorkbook();
        }
        CreationHelper ch = workbook.getCreationHelper();
        DataFormat df = ch.createDataFormat();

        sheet       = workbook.createSheet( ReportName );
        sheet.createFreezePane(0, 4,0,4);
        boolean bufferQtyAdded = false;

        sheet.setSelected( true );
        Font titleFont = workbook.createFont();
        titleFont.setFontHeightInPoints ( ( short ) 8 );
        titleFont.setBoldweight ( Font.BOLDWEIGHT_BOLD );
        titleFont.setFontName( "verdana" );
        titleFont.setColor ( IndexedColors.BLACK.getIndex());

        Font headerFont = workbook.createFont();
        headerFont.setFontHeightInPoints ( ( short ) 8 );
        headerFont.setBoldweight ( Font.BOLDWEIGHT_BOLD );
        headerFont.setFontName( "verdana" );
        headerFont.setColor ( IndexedColors.BLACK.getIndex());

        Font textFont = workbook.createFont();
        textFont.setFontHeightInPoints ( ( short ) 8 );
        textFont.setBoldweight ( Font.BOLDWEIGHT_NORMAL );
        textFont.setFontName( "verdana" );
        textFont.setColor ( IndexedColors.BLACK.getIndex());

        CellStyle titleStyle  = workbook.createCellStyle ( );
        titleStyle.setBorderBottom ( CellStyle.BORDER_THIN );
        titleStyle.setBorderTop ( CellStyle.BORDER_THIN );
        titleStyle.setBorderLeft ( CellStyle.BORDER_THIN );
        titleStyle.setBorderRight ( CellStyle.BORDER_THIN );
        titleStyle.setAlignment ( CellStyle.ALIGN_CENTER );
        titleStyle.setWrapText ( true );
        titleStyle.setFont ( titleFont );

        CellStyle headerStyle  = workbook.createCellStyle ( );
        headerStyle.setBorderBottom ( CellStyle.BORDER_THIN );
        headerStyle.setBorderTop ( CellStyle.BORDER_THIN );
        headerStyle.setBorderLeft ( CellStyle.BORDER_THIN );
        headerStyle.setBorderRight ( CellStyle.BORDER_THIN );
        headerStyle.setAlignment ( CellStyle.ALIGN_CENTER );
        headerStyle.setWrapText ( true );
        headerStyle.setFont ( headerFont );

        CellStyle productValueStyle  = workbook.createCellStyle ( );
        productValueStyle.setBorderBottom ( CellStyle.BORDER_THIN );
        productValueStyle.setBorderTop ( CellStyle.BORDER_THIN );
        productValueStyle.setBorderLeft ( CellStyle.BORDER_THIN );
        productValueStyle.setBorderRight ( CellStyle.BORDER_THIN );
        productValueStyle.setAlignment ( CellStyle.ALIGN_RIGHT );
        productValueStyle.setWrapText ( true );
        productValueStyle.setFont ( textFont );
        productValueStyle.setDataFormat( df.getFormat( "#,##0" ) );

        CellStyle productValueBoldStyle  = workbook.createCellStyle ( );
        productValueBoldStyle.setBorderBottom ( CellStyle.BORDER_THIN );
        productValueBoldStyle.setBorderTop ( CellStyle.BORDER_THIN );
        productValueBoldStyle.setBorderLeft ( CellStyle.BORDER_THIN );
        productValueBoldStyle.setBorderRight ( CellStyle.BORDER_THIN );
        productValueBoldStyle.setAlignment ( CellStyle.ALIGN_RIGHT );
        productValueBoldStyle.setWrapText ( true );
        productValueBoldStyle.setFont ( headerFont );
        productValueBoldStyle.setDataFormat( df.getFormat( "#,##0" ) );

        CellStyle thousandValueStyle  = workbook.createCellStyle ( );
        thousandValueStyle.setBorderBottom ( CellStyle.BORDER_THIN );
        thousandValueStyle.setBorderTop ( CellStyle.BORDER_THIN );
        thousandValueStyle.setBorderLeft ( CellStyle.BORDER_THIN );
        thousandValueStyle.setBorderRight ( CellStyle.BORDER_THIN );
        thousandValueStyle.setAlignment ( CellStyle.ALIGN_RIGHT );
        thousandValueStyle.setWrapText ( true );
        thousandValueStyle.setFont ( textFont );
        thousandValueStyle.setDataFormat( df.getFormat( "# ?/?" ) );

        CellStyle yieldStyle  = workbook.createCellStyle ( );
        yieldStyle.setBorderBottom ( CellStyle.BORDER_THIN );
        yieldStyle.setBorderTop ( CellStyle.BORDER_THIN );
        yieldStyle.setBorderLeft ( CellStyle.BORDER_THIN );
        yieldStyle.setBorderRight ( CellStyle.BORDER_THIN );
        yieldStyle.setAlignment ( CellStyle.ALIGN_RIGHT );
        yieldStyle.setWrapText ( true );
        yieldStyle.setFont ( textFont );
        yieldStyle.setDataFormat( df.getFormat( "0%" ) );

        CellStyle productStyle  = workbook.createCellStyle ( );
        productStyle.setBorderBottom ( CellStyle.BORDER_THIN );
        productStyle.setBorderTop ( CellStyle.BORDER_THIN );
        productStyle.setBorderLeft ( CellStyle.BORDER_THIN );
        productStyle.setBorderRight ( CellStyle.BORDER_THIN );
        productStyle.setAlignment ( CellStyle.ALIGN_LEFT );
        productStyle.setWrapText ( true );
        productStyle.setFont ( textFont );

        CellStyle dateStyle  = workbook.createCellStyle ( );
        dateStyle.setBorderBottom ( CellStyle.BORDER_THIN );
        dateStyle.setBorderTop ( CellStyle.BORDER_THIN );
        dateStyle.setBorderLeft ( CellStyle.BORDER_THIN );
        dateStyle.setBorderRight ( CellStyle.BORDER_THIN );
        dateStyle.setAlignment ( CellStyle.ALIGN_RIGHT );
        dateStyle.setWrapText ( true );
        dateStyle.setFont ( textFont );
        dateStyle.setDataFormat( df.getFormat( "m/d/yy" ) );

        //SETTING HEADINGS
        final String fabPartStr = "Wafer Part";
        final String fgPartStr = "FG Part";
        final String chipSetStr = "Chip Set";
        /*final String productLineStr = "Product Line";
        final String chipFamilyStr = "Chip Family";
        final String process = "Process";
        final String waferCost = "Wafer Cost";*/
        final String currentQtrFct = DataDumpReportsDAO.getQuarterString(0)+" Fct";
        final String nextQtrFct = DataDumpReportsDAO.getQuarterString(1)+" Fct";
        final String nextNextQtrFct = DataDumpReportsDAO.getQuarterString(2)+" Fct";
        final String nextNextNextQtrFct = DataDumpReportsDAO.getQuarterString(3)+" Fct";
        final String currentQtrShipments = DataDumpReportsDAO.getQuarterString(0)+" Shipment";
        final String currentQtrBacklog = DataDumpReportsDAO.getQuarterString(0)+" Backlog";
        final String bufferQtyStr = "Buffer Qty";
        final String diePerPackageQtyStr = "Dies Per Package";
        final String fabYieldStr = "Fab Std Yield";
        final String sortYieldStr = "Sort Std Yield";
        final String assemblyYieldStr = "Assembly Std Yield";
        final String ftYieldStr = "FT Yield";
        final String totalYieldStr = "Total Yield";
        final String gdwStr	= "GDW";
        final String ndpwStr = "NDPW";
        final String waitingForWSStr = "Waiting For W/S (Wfr)";
        final String fabStr = "Fab(Wfr)";
        final String wsStr = "Wafer Store(Wfr)";
        final String sortStr = "Sort(Wfr)";
        final String dieBankStr = "Die Bank";
        final String backEndDieStr = "Total Front End Die";
        final String assemblyStr = "Assembly";
        final String preTestStr = "Pre Test";
        final String finalTestStr =  "Final Test";
        final String eolStr = "EOL";
        final String fgStr = "Finished Goods";
        final String totDieAvailableStr = "Total Back End Die";
        final String fabCycleTime = "Fab Cycle Time";
        final String sortCycleTime = "Sort Cycle Time";
        final String assemblyCycleTime = "Assembly Cycle Time";
        final String testCycleTime = "Test Cycle Time";
        final String eolCycleTime = "EOL Cycle Time";
        final String totalCycleTime = "Cycle Time";
                
        Calendar cal = Calendar.getInstance();
        int year = cal.get( Calendar.YEAR );
        int qtrNo = DateUtil.getQuarterOfMonth(cal.get(Calendar.MONTH)+1);
        int qtrStartMth = DateUtil.getStartMonthOfQtr ( qtrNo );
        int[] cycleTimes = new int[12];
        String[] monthArray = new String[12];

        cal.clear();
        cal.set( year, qtrStartMth-1, 1 ); //setting to current qtr start month
        final String m1Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase();
        final String b1Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+" ";
        final String w1Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"  ";
        final String p1Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"   ";
        cal.add( Calendar.MONTH, 1 );
        final String m2Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase();
        final String b2Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+" ";
        final String w2Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"  ";
        final String p2Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"   ";
        cal.add( Calendar.MONTH, 1 );
        final String m3Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase();
        final String b3Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+" ";
        final String w3Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"  ";
        final String p3Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"   ";
        cal.add( Calendar.MONTH, 1 );
        final String m4Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase();
        final String b4Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+" ";
        final String w4Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"  ";
        final String p4Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"   ";
        cal.add( Calendar.MONTH, 1 );
        final String m5Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase();
        final String b5Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+" ";
        final String w5Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"  ";
        final String p5Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"   ";
        cal.add( Calendar.MONTH, 1 );
        final String m6Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase();
        final String b6Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+" ";
        final String w6Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"  ";
        final String p6Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"   ";
        cal.add( Calendar.MONTH, 1 );
        final String m7Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase();
        final String b7Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+" ";
        final String w7Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"  ";
        final String p7Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"   ";
        cal.add( Calendar.MONTH, 1 );
        final String m8Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase();
        final String b8Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+" ";
        final String w8Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"  ";
        final String p8Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"   ";
        cal.add( Calendar.MONTH, 1 );
        final String m9Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase();
        final String b9Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+" ";
        final String w9Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"  ";
        final String p9Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"   ";
        cal.add( Calendar.MONTH, 1 );
        final String m10Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase();
        final String b10Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+" ";
        final String w10Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"  ";
        final String p10Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"   ";
        cal.add( Calendar.MONTH, 1 );
        final String m11Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase();
        final String b11Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+" ";
        final String w11Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"  ";
        final String p11Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"   ";
        cal.add( Calendar.MONTH, 1 );
        final String m12Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase();
        final String b12Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+" ";
        final String w12Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"  ";
        final String p12Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"   ";
        
        String headers[] = { fabPartStr, fgPartStr, currentQtrFct, currentQtrShipments, 
        		currentQtrBacklog, nextQtrFct, nextNextQtrFct, nextNextNextQtrFct, bufferQtyStr,diePerPackageQtyStr,
        		fabYieldStr, sortYieldStr, assemblyYieldStr, ftYieldStr, totalYieldStr, gdwStr, ndpwStr,
                waitingForWSStr,
                fabStr, wsStr, sortStr, dieBankStr, backEndDieStr, assemblyStr, preTestStr, finalTestStr, eolStr, fgStr, 
                totDieAvailableStr, m1Str, m2Str, m3Str, m4Str, m5Str, m6Str, m7Str, m8Str, m9Str, m10Str, m11Str, m12Str
                ,b1Str, b2Str, b3Str, b4Str, b5Str, b6Str, b7Str, b8Str, b9Str, b10Str, b11Str, b12Str
                , fabCycleTime, sortCycleTime, assemblyCycleTime, testCycleTime,eolCycleTime,totalCycleTime
                ,w1Str, w2Str, w3Str, w4Str, w5Str, w6Str, w7Str, w8Str, w9Str, w10Str, w11Str, w12Str
                ,p1Str, p2Str, p3Str, p4Str, p5Str, p6Str, p7Str, p8Str, p9Str, p10Str, p11Str, p12Str};
        
        List<String> columnList = Arrays.asList( headers );
        try
        {
	        Row row = sheet.createRow( 0 );
	        Cell cell = mergeCells( sheet, 0, (short)0, 0, (short)(headers.length-1), titleStyle );
	        setCellValue( cell, ch.createRichTextString("Wafer Build Plan"), titleStyle );
	        
	        row = sheet.createRow( 1 );
	        setCellValue( row, (short)columnList.indexOf(m1Str), 5, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(m2Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(m3Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(m4Str), 5, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(m5Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(m6Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(m7Str), 5, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(m8Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(m9Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(m10Str), 5, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(m11Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(m12Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        
	        cal.clear();
	        cal.set( year, qtrStartMth-1, 1 );
	        if( cal.getTime().before( new Date() ) )
	        {
	        	setCellValue( row, (short)columnList.indexOf(b1Str), 0, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        	cycleTimes[0] = 0;
	        }
	        else
	        {
	        	setCellValue( row, (short)columnList.indexOf(b1Str), 5, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        	cycleTimes[0] = 4;
	        }
	        cal.add( Calendar.MONTH, 1 );
	        if( cal.getTime().before( new Date() ) )
	        {
	        	setCellValue( row, (short)columnList.indexOf(b2Str), 0, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        	cycleTimes[1] = 0;
	        }
	        else
	        {
	        	setCellValue( row, (short)columnList.indexOf(b2Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        	cycleTimes[1] = 4;
	        }
	        cal.add( Calendar.MONTH, 1 );
	        if( cal.getTime().before( new Date() ) )
	        {
	        	setCellValue( row, (short)columnList.indexOf(b3Str), 0, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        	cycleTimes[2] = 0;
	        }
	        else
	        {
	        	setCellValue( row, (short)columnList.indexOf(b3Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        	cycleTimes[2] = 5;
	        }

	        setCellValue( row, (short)columnList.indexOf(b4Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(b5Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(b6Str), 5, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(b7Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(b8Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(b9Str), 5, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(b10Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(b11Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(b12Str), 5, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        cycleTimes[3] = 4;
	        cycleTimes[4] = 4;
	        cycleTimes[5] = 5;
	        cycleTimes[6] = 4;
	        cycleTimes[7] = 4;
	        cycleTimes[8] = 5;
	        cycleTimes[9] = 4;
	        cycleTimes[10] = 4;
	        cycleTimes[11] = 5;

	        monthArray[0] = w1Str;
	        monthArray[1] = w2Str;
	        monthArray[2] = w3Str;
	        monthArray[3] = w4Str;
	        monthArray[4] = w5Str;
	        monthArray[5] = w6Str;
	        monthArray[6] = w7Str;
	        monthArray[7] = w8Str;
	        monthArray[8] = w9Str;
	        monthArray[9] = w10Str;
	        monthArray[10] = w11Str;
	        monthArray[11] = w12Str;
	        
	        setCellValue( row, (short)columnList.indexOf(w1Str), cycleTimes[0], productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(w2Str), cycleTimes[1], productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(w3Str), cycleTimes[2], productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(w4Str), cycleTimes[3], productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(w5Str), cycleTimes[4], productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(w6Str), cycleTimes[5], productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(w7Str), cycleTimes[6], productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(w8Str), cycleTimes[7], productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(w9Str), cycleTimes[8], productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(w10Str), cycleTimes[9], productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(w11Str), cycleTimes[10], productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(w12Str), cycleTimes[11], productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        
	        row = sheet.createRow( 2 );
	        
	        
	        cell = mergeCells( sheet, 2, (short)columnList.indexOf( fabYieldStr ), 2, (short)columnList.indexOf( ftYieldStr ), titleStyle );
	        setCellValue( cell, ch.createRichTextString("Standard Yields"), titleStyle );
	
	        cell = mergeCells( sheet, 2, (short)columnList.indexOf(waitingForWSStr), 2, (short)columnList.indexOf(fgStr), titleStyle );
	        setCellValue( cell, ch.createRichTextString("WIP/Inventory"), titleStyle );
	
	        cell = mergeCells( sheet, 2, (short)columnList.indexOf(m1Str), 2, (short)columnList.indexOf(m12Str), titleStyle );
	        setCellValue( cell, ch.createRichTextString("Unit Demand"), titleStyle );
	
	        cell = mergeCells( sheet, 2, (short)columnList.indexOf(b1Str), 2, (short)columnList.indexOf(b12Str), titleStyle );
	        setCellValue( cell, ch.createRichTextString("Unsupplied Forecast"), titleStyle );
	
	        cell = mergeCells( sheet, 2, (short)columnList.indexOf(w1Str), 2, (short)columnList.indexOf(w12Str), titleStyle );
	        setCellValue( cell, ch.createRichTextString("Wafer Purchase Period -Die"), titleStyle );
	        
	        cell = mergeCells( sheet, 2, (short)columnList.indexOf(p1Str), 2, (short)columnList.indexOf(p12Str), titleStyle );
	        setCellValue( cell, ch.createRichTextString("Wafer Purchase Period"), titleStyle );
	        
	        cell = mergeCells( sheet, 2, (short)columnList.indexOf(fabCycleTime), 2, (short)columnList.indexOf(eolCycleTime), titleStyle );
	        setCellValue( cell, ch.createRichTextString("Standard Cycle Times"), titleStyle );
	        /* 
	        cell = mergeCells( sheet, 1, (short)columnList.indexOf(__m1Str), 1, (short)columnList.indexOf(nextNextQtrBuildFCStr), titleStyle );
	        setCellValue( cell, nextNextQtrStr + " Forecast", titleStyle );
	        */
	        row = sheet.createRow ( 3 );
	        for ( int i = 0; i < headers.length; i++ )
	        {
	            cell    = row.createCell( i );
	            setCellValue( cell, ch.createRichTextString(headers[i]), headerStyle );
	            
	            if ( headers[i].equalsIgnoreCase( fabYieldStr ) || headers[i].equalsIgnoreCase( sortYieldStr ) || 
	            		headers[i].equalsIgnoreCase( assemblyYieldStr) || headers[i].equalsIgnoreCase( ftYieldStr ) ||
						headers[i].equalsIgnoreCase( waitingForWSStr ) || headers[i].equalsIgnoreCase( fabStr ) || 
						headers[i].equalsIgnoreCase( wsStr ) || headers[i].equalsIgnoreCase( sortStr ) || headers[i].equalsIgnoreCase( dieBankStr ) ||
						headers[i].equalsIgnoreCase( backEndDieStr ) || headers[i].equalsIgnoreCase( assemblyStr ) || headers[i].equalsIgnoreCase( preTestStr ) ||
						headers[i].equalsIgnoreCase( finalTestStr ) || headers[i].equalsIgnoreCase( eolStr ) || headers[i].equalsIgnoreCase( fgStr ) || 
						headers[i].equalsIgnoreCase( fabCycleTime ) || headers[i].equalsIgnoreCase( sortCycleTime ) || headers[i].equalsIgnoreCase( assemblyCycleTime ) ||
						headers[i].equalsIgnoreCase( testCycleTime ) || headers[i].equalsIgnoreCase( eolCycleTime ) || headers[i].equalsIgnoreCase( gdwStr ) ||
						headers[i].equalsIgnoreCase( m1Str ) || headers[i].equalsIgnoreCase( m2Str ) || headers[i].equalsIgnoreCase( m3Str ) || headers[i].equalsIgnoreCase( m4Str ) || 
						headers[i].equalsIgnoreCase( m5Str ) || headers[i].equalsIgnoreCase( m6Str ) || headers[i].equalsIgnoreCase( m7Str ) || headers[i].equalsIgnoreCase( m8Str ) || 
						headers[i].equalsIgnoreCase( m9Str ) || headers[i].equalsIgnoreCase( m10Str ) || headers[i].equalsIgnoreCase( m11Str ) || headers[i].equalsIgnoreCase( m12Str ) ||
						headers[i].equalsIgnoreCase( b1Str ) || headers[i].equalsIgnoreCase( b2Str ) || headers[i].equalsIgnoreCase( b3Str ) || headers[i].equalsIgnoreCase( b4Str ) || 
						headers[i].equalsIgnoreCase( b5Str ) || headers[i].equalsIgnoreCase( b6Str ) || headers[i].equalsIgnoreCase( b7Str ) || headers[i].equalsIgnoreCase( b8Str ) || 
						headers[i].equalsIgnoreCase( b9Str ) || headers[i].equalsIgnoreCase( b10Str ) || headers[i].equalsIgnoreCase( b11Str ) || headers[i].equalsIgnoreCase( b12Str ) ||
						headers[i].equalsIgnoreCase( w1Str ) || headers[i].equalsIgnoreCase( w2Str ) || headers[i].equalsIgnoreCase( w3Str ) || headers[i].equalsIgnoreCase( w4Str ) || 
						headers[i].equalsIgnoreCase( w5Str ) || headers[i].equalsIgnoreCase( w6Str ) || headers[i].equalsIgnoreCase( w7Str ) || headers[i].equalsIgnoreCase( w8Str ) || 
						headers[i].equalsIgnoreCase( w9Str ) || headers[i].equalsIgnoreCase( w10Str ) || headers[i].equalsIgnoreCase( w11Str ) || headers[i].equalsIgnoreCase( w12Str )
					)
	            {
	                sheet.setColumnWidth( i, 0 );// Change this to sheet.setColumnWidth( i, 0  ) to hide columns
	            }
	            else if(  headers[i].equalsIgnoreCase( fgPartStr ) )
	            {
	            	sheet.setColumnWidth( i, ( ( ( 30 ) * 256 ) ) );
	            }
	            else if(  headers[i].equalsIgnoreCase( chipSetStr ) )
	            {
	            	sheet.setColumnWidth( i, ( ( ( 18 ) * 256 ) ) );
	            }
	            else
	            {
	                sheet.setColumnWidth( i, ( ( ( 12 ) * 256 ) ) );
	            }
	        }
	        
	        int nextRowNumber   = 4;
	        int nextColumnIdx = 0;
	        int mergerIdx = 0;
	        int prevCycleTime = 0;
	        String prevFabPart = "";
	        String formula = "";
	        mergerIdx = nextRowNumber + 1;
	        for ( WaferStartData waferStartData: waferStartDataList ) 
	        {
	        	bufferQtyAdded = false;
	        	nextColumnIdx = 0;
	        	row = sheet.createRow( nextRowNumber );
	        	nextRowNumber++;

	        	setCellValue( row, (short)nextColumnIdx++, ch.createRichTextString(waferStartData.getFabPartNumber()), productStyle  );
	        	setCellValue( row, (short)nextColumnIdx++, ch.createRichTextString(waferStartData.getFgPartNumber()), productStyle  );
	        	/*setCellValue( row, (short)nextColumnIdx++, ch.createRichTextString(waferStartData.getChipSet()), productStyle  );
	        	setCellValue( row, (short)nextColumnIdx++, ch.createRichTextString(waferStartData.getProductLine()), productStyle  );
	        	setCellValue( row, (short)nextColumnIdx++, ch.createRichTextString(waferStartData.getChipFamily()), productStyle  );
	            setCellValue( row, (short)nextColumnIdx++, ch.createRichTextString(waferStartData.getProcess()), productStyle  );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getWaferCost(), productStyle, Cell.CELL_TYPE_NUMERIC   );*/
                if("month".equalsIgnoreCase(fctframe)) {
                    String qtrformula = getCellReference(columnList.indexOf(m1Str), nextRowNumber)+
                                    "+"+getCellReference(columnList.indexOf(m2Str), nextRowNumber)+
                                    "+"+getCellReference(columnList.indexOf(m3Str), nextRowNumber);
                    setCellFormula( row, (short)nextColumnIdx++, qtrformula, productValueStyle );
                } else {
                    setCellValue( row, (short)nextColumnIdx++, waferStartData.getCurrent_Qtr_Forecast(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
                }

	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getCurrent_Qtr_Shipped_Qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getCurrent_Qtr_Backlog(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
                if("month".equalsIgnoreCase(fctframe)) {
                    String qtrformula = getCellReference(columnList.indexOf(m4Str), nextRowNumber)+
                                    "+"+getCellReference(columnList.indexOf(m5Str), nextRowNumber)+
                                    "+"+getCellReference(columnList.indexOf(m6Str), nextRowNumber);
                    setCellFormula( row, (short)nextColumnIdx++, qtrformula, productValueStyle );

                    qtrformula = getCellReference(columnList.indexOf(m7Str), nextRowNumber)+
                                    "+"+getCellReference(columnList.indexOf(m8Str), nextRowNumber)+
                                    "+"+getCellReference(columnList.indexOf(m9Str), nextRowNumber);
                    setCellFormula( row, (short)nextColumnIdx++, qtrformula, productValueStyle );

                    qtrformula = getCellReference(columnList.indexOf(m10Str), nextRowNumber)+
                                    "+"+getCellReference(columnList.indexOf(m11Str), nextRowNumber)+
                                    "+"+getCellReference(columnList.indexOf(m12Str), nextRowNumber);
                    setCellFormula( row, (short)nextColumnIdx++, qtrformula, productValueStyle );
                } else {
                    setCellValue( row, (short)nextColumnIdx++, waferStartData.getQ1_Forecast(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
                    setCellValue( row, (short)nextColumnIdx++, waferStartData.getQ2_Forecast(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	                setCellValue( row, (short)nextColumnIdx++, waferStartData.getQ3_Forecast(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
                }


	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getFg_min_level_Qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getDiePerPackage(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getFab_Yield(), yieldStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getSort_Yield(), yieldStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getAssembly_Yield(), yieldStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getTest_Yield(), yieldStyle, Cell.CELL_TYPE_NUMERIC   );
	            String totalYieldFormula = getAlphaforIdx(columnList.indexOf(fabYieldStr))+nextRowNumber+
	            "*"+getAlphaforIdx(columnList.indexOf(sortYieldStr))+nextRowNumber+
	            "*"+getAlphaforIdx(columnList.indexOf(assemblyYieldStr))+nextRowNumber+
	            "*"+getAlphaforIdx(columnList.indexOf(ftYieldStr))+nextRowNumber;
	            setCellFormula( row, (short)nextColumnIdx++, totalYieldFormula, yieldStyle );
	            
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getGdw()<1?1:waferStartData.getGdw(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            String netDieFormula = getAlphaforIdx(columnList.indexOf(gdwStr))+nextRowNumber+
	            "*"+getAlphaforIdx(columnList.indexOf(totalYieldStr))+nextRowNumber;
	            setCellFormula( row, (short)nextColumnIdx++, netDieFormula, productValueStyle );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getOpen_PO_Qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getFab_Qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getWafer_Store_Qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getSort_Qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getDb_Qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	           
	            /*
	            if( prevFabPart != null && prevFabPart.equalsIgnoreCase( waferStartData.getFabPartNumber() ) )
	            {
		            formula = "IF("+getAlphaforIdx(columnList.indexOf( totDieAvailableStr ))+(nextRowNumber-1)+
	            	"> SUM("+getAlphaforIdx(columnList.indexOf(m1Str))+( nextRowNumber - 1 )+":"+
	            	getAlphaforIdx(columnList.indexOf( m12Str ))+( nextRowNumber -1 )+ "), "+
	            	getAlphaforIdx(columnList.indexOf( backEndDieStr ))+( nextRowNumber -1 ) +"- (SUM(" +
	            	getAlphaforIdx(columnList.indexOf( m1Str ))+( nextRowNumber - 1 )+":"+
		            getAlphaforIdx(columnList.indexOf( m12Str ))+( nextRowNumber -1 )+")- SUM(" +
		            getAlphaforIdx(columnList.indexOf( assemblyStr ))+( nextRowNumber -1 )+":"+
		            getAlphaforIdx(columnList.indexOf( fgStr ))+( nextRowNumber -1 )+")), 0)";
	            }
	            else
	            {*/
		            formula = "("+getAlphaforIdx(columnList.indexOf(waitingForWSStr))+nextRowNumber+
	            	"+"+getAlphaforIdx(columnList.indexOf(fabStr))+nextRowNumber+")"+
	            	"*"+getAlphaforIdx(columnList.indexOf(fabYieldStr))+nextRowNumber+
	            	"*"+getAlphaforIdx(columnList.indexOf(sortYieldStr))+nextRowNumber+
	            	"*"+getAlphaforIdx(columnList.indexOf(assemblyYieldStr))+nextRowNumber+
	            	"*"+getAlphaforIdx(columnList.indexOf(ftYieldStr))+nextRowNumber+
	            	"*"+getAlphaforIdx(columnList.indexOf(gdwStr))+nextRowNumber+
	            	"+("+getAlphaforIdx(columnList.indexOf( wsStr ))+nextRowNumber+
	            	"+"+getAlphaforIdx(columnList.indexOf( sortStr ))+nextRowNumber+")"+
	            	"*"+getAlphaforIdx(columnList.indexOf(sortYieldStr))+nextRowNumber+
	            	"*"+getAlphaforIdx(columnList.indexOf(assemblyYieldStr))+nextRowNumber+
	            	"*"+getAlphaforIdx(columnList.indexOf(ftYieldStr))+nextRowNumber+
	            	"*"+getAlphaforIdx(columnList.indexOf(gdwStr))+nextRowNumber+
	            	"+("+getAlphaforIdx(columnList.indexOf( dieBankStr ))+nextRowNumber+")"+
	            	"*"+getAlphaforIdx(columnList.indexOf(assemblyYieldStr))+nextRowNumber+
	            	"*"+getAlphaforIdx(columnList.indexOf(ftYieldStr))+nextRowNumber;
	            //}
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getAssembly_Qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getPreTest_Qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getTest_Qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getEol_Qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getFg_Qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            /*String totalDieAvailableFormula = getAlphaforIdx(columnList.indexOf( backEndDieStr ))+nextRowNumber + 
	            	"+("+getAlphaforIdx(columnList.indexOf( assemblyStr ))+nextRowNumber+")"+
	            	"*"+getAlphaforIdx(columnList.indexOf(assemblyYieldStr))+nextRowNumber+
	            	"*"+getAlphaforIdx(columnList.indexOf(ftYieldStr))+nextRowNumber+
	            	"+("+getAlphaforIdx(columnList.indexOf( preTestStr ))+nextRowNumber+")"+
	            	"*"+getAlphaforIdx(columnList.indexOf(ftYieldStr))+nextRowNumber+
	            	"+("+getAlphaforIdx(columnList.indexOf( finalTestStr ))+nextRowNumber+")"+
	            	"*"+getAlphaforIdx(columnList.indexOf(ftYieldStr))+nextRowNumber+
	            	"+"+getAlphaforIdx(columnList.indexOf( eolStr ))+nextRowNumber+
	            	"+"+getAlphaforIdx(columnList.indexOf( fgStr ))+nextRowNumber	;*/
	            
	            String totalDieAvailableFormula = "("+getAlphaforIdx(columnList.indexOf( assemblyStr ))+nextRowNumber+")"+
            	"*"+getAlphaforIdx(columnList.indexOf(assemblyYieldStr))+nextRowNumber+
            	"*"+getAlphaforIdx(columnList.indexOf(ftYieldStr))+nextRowNumber+
            	"+("+getAlphaforIdx(columnList.indexOf( preTestStr ))+nextRowNumber+")"+
            	"*"+getAlphaforIdx(columnList.indexOf(ftYieldStr))+nextRowNumber+
            	"+("+getAlphaforIdx(columnList.indexOf( finalTestStr ))+nextRowNumber+")"+
            	"*"+getAlphaforIdx(columnList.indexOf(ftYieldStr))+nextRowNumber+
            	"+"+getAlphaforIdx(columnList.indexOf( eolStr ))+nextRowNumber+
            	"+"+getAlphaforIdx(columnList.indexOf( fgStr ))+nextRowNumber	;
	            setCellFormula( row, (short)nextColumnIdx++, totalDieAvailableFormula, productValueStyle );
	            
	            boolean reduceShipQty = false; 
	            String currentQtrQty = "";
                if ((waferStartData.getCurrent_Qtr_Backlog() + waferStartData.getCurrent_Qtr_Shipped_Qty()) > waferStartData.getCurrent_Qtr_Forecast()) {
                    currentQtrQty = currentQtrBacklog;
                } else {
                    currentQtrQty = currentQtrFct;
                    reduceShipQty = true;
                }
                //formula  = "IF( "+ getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber +" > (" +getAlphaforIdx( columnList.indexOf( currentQtrQty ) )+nextRowNumber + "/13)*4, 0, "+  "("+getAlphaforIdx( columnList.indexOf( currentQtrQty ) )+nextRowNumber + "/13)*4 -"+ getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber +")";
                if( reduceShipQty )
                {
                	formula = "month".equalsIgnoreCase(fctframe)? waferStartData.getM1_fc_qty()+"" : "IF(((" + getAlphaforIdx(columnList.indexOf(currentQtrQty)) + nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m1Str))+ 2 )+")>" +getAlphaforIdx(columnList.indexOf( currentQtrShipments ))+ nextRowNumber +",((" + getAlphaforIdx(columnList.indexOf(currentQtrQty)) + nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m1Str))+ 2 )+")-" +getAlphaforIdx(columnList.indexOf( currentQtrShipments ))+ nextRowNumber +", 0)" ;
                }
                else
                {
                	formula = "month".equalsIgnoreCase(fctframe)? waferStartData.getM1_fc_qty()+"" : "((" + getAlphaforIdx(columnList.indexOf(currentQtrQty)) + nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m1Str))+ 2 )+")" ;
                }
                setCellFormula(row, (short) nextColumnIdx++, formula, productValueStyle);
                
                //add the buffer quantity to this months forecast if this is not the current month
                /*if (cycleTimes[1] != 0 && bufferQtyAdded == false) {
                    formula = "month".equalsIgnoreCase(fctframe)? waferStartData.getM2_fc_qty()+"" : "((" + getAlphaforIdx(columnList.indexOf(currentQtrQty)) + nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m2Str))+ 2 )+")";
                    formula += "+" + getAlphaforIdx(columnList.indexOf(bufferQtyStr)) + nextRowNumber;
                    bufferQtyAdded = true;
                } else {
                    formula = "month".equalsIgnoreCase(fctframe)? waferStartData.getM2_fc_qty()+"" : "((" + getAlphaforIdx(columnList.indexOf(currentQtrQty)) + nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m2Str))+ 2 )+")";
                }*/

                if( reduceShipQty )
                {
                	formula = "month".equalsIgnoreCase(fctframe)? waferStartData.getM2_fc_qty()+"" : "IF(((" + getAlphaforIdx(columnList.indexOf(currentQtrQty)) + nextRowNumber + "/13)*("+ (getAlphaforIdx(columnList.indexOf(m2Str))+ 2 )+ "+"+ (getAlphaforIdx(columnList.indexOf(m1Str))+ 2 )+  "))>" + getAlphaforIdx(columnList.indexOf( currentQtrShipments ))+ nextRowNumber +",(("+ getAlphaforIdx(columnList.indexOf(currentQtrQty)) + nextRowNumber + "/13)*("+ (getAlphaforIdx(columnList.indexOf(m2Str))+ 2 )+ "+"+ (getAlphaforIdx(columnList.indexOf(m1Str))+ 2 )+  "))-" + getAlphaforIdx(columnList.indexOf( currentQtrShipments ))+ nextRowNumber+ "-" + getAlphaforIdx(columnList.indexOf( m1Str ))+ nextRowNumber +",0)"  ;
                }
                else
                {
                	formula = "month".equalsIgnoreCase(fctframe)? waferStartData.getM2_fc_qty()+"" : "((" + getAlphaforIdx(columnList.indexOf(currentQtrQty)) + nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m2Str))+ 2 )+")";
                }

                if (cycleTimes[1] != 0 && bufferQtyAdded == false) 
                {
                	formula += "+" + getAlphaforIdx(columnList.indexOf(bufferQtyStr)) + nextRowNumber;
                	bufferQtyAdded = true;
            	}                 
                setCellFormula(row, (short) nextColumnIdx++, formula, productValueStyle);

                if( reduceShipQty )
                {
                	formula = "month".equalsIgnoreCase(fctframe)? waferStartData.getM2_fc_qty()+"" : "IF(" + getAlphaforIdx(columnList.indexOf(currentQtrQty)) + nextRowNumber + ">"+ (getAlphaforIdx(columnList.indexOf(currentQtrShipments))+ nextRowNumber )+ ","+ getAlphaforIdx(columnList.indexOf(currentQtrQty)) + nextRowNumber + "-" +getAlphaforIdx(columnList.indexOf( m1Str ))+ nextRowNumber +"-"+getAlphaforIdx(columnList.indexOf( m2Str ))+ nextRowNumber + "-" + (getAlphaforIdx(columnList.indexOf(currentQtrShipments))+ nextRowNumber ) +" , 0)";
                }
                else
                {
                	formula = "month".equalsIgnoreCase(fctframe)? waferStartData.getM3_fc_qty()+"" : "((" + getAlphaforIdx(columnList.indexOf(currentQtrQty)) + nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m3Str))+ 2 )+")";
                }
                
                if (cycleTimes[2] != 0 && bufferQtyAdded == false) 
                {
                    formula += "+" + getAlphaforIdx(columnList.indexOf(bufferQtyStr)) + nextRowNumber;
                    bufferQtyAdded = true;
                }
                
                setCellFormula(row, (short) nextColumnIdx++, formula, productValueStyle);

                if (cycleTimes[3] != 0 && bufferQtyAdded == false) {
                    formula = "month".equalsIgnoreCase(fctframe)? waferStartData.getM4_fc_qty()+"" : "((" + getAlphaforIdx(columnList.indexOf(nextQtrFct)) + nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m4Str))+ 2 )+")";
                    formula += "+" + getAlphaforIdx(columnList.indexOf(bufferQtyStr)) + nextRowNumber;
                    bufferQtyAdded = true;
                } else {
                    formula = "month".equalsIgnoreCase(fctframe)? waferStartData.getM4_fc_qty()+"" : "((" + getAlphaforIdx(columnList.indexOf(nextQtrFct)) + nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m4Str))+ 2 )+")";
                }
	            
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            formula  = "month".equalsIgnoreCase(fctframe)? waferStartData.getM5_fc_qty()+"" : "(("+getAlphaforIdx( columnList.indexOf( nextQtrFct ) )+nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m5Str))+ 2 )+")";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            formula  = "month".equalsIgnoreCase(fctframe)? waferStartData.getM6_fc_qty()+"" : "(("+getAlphaforIdx( columnList.indexOf( nextQtrFct ) )+nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m6Str))+ 2 )+")";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            formula  = "month".equalsIgnoreCase(fctframe)? waferStartData.getM7_fc_qty()+"" : "(("+getAlphaforIdx( columnList.indexOf( nextNextQtrFct ) )+nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m7Str))+ 2 )+")";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            formula  = "month".equalsIgnoreCase(fctframe)? waferStartData.getM8_fc_qty()+"" : "(("+getAlphaforIdx( columnList.indexOf( nextNextQtrFct ) )+nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m8Str))+ 2 )+")";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            formula  = "month".equalsIgnoreCase(fctframe)? waferStartData.getM9_fc_qty()+"" : "(("+getAlphaforIdx( columnList.indexOf( nextNextQtrFct ) )+nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m9Str))+ 2 )+")";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            formula  = "month".equalsIgnoreCase(fctframe)? waferStartData.getM10_fc_qty()+"" : "(("+getAlphaforIdx( columnList.indexOf( nextNextNextQtrFct ) )+nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m10Str))+ 2 )+")";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            formula  = "month".equalsIgnoreCase(fctframe)? waferStartData.getM11_fc_qty()+"" : "(("+getAlphaforIdx( columnList.indexOf( nextNextNextQtrFct ) )+nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m11Str))+ 2 )+")";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            formula  = "month".equalsIgnoreCase(fctframe)? waferStartData.getM12_fc_qty()+"" : "(("+getAlphaforIdx( columnList.indexOf( nextNextNextQtrFct ) )+nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m12Str))+ 2 )+")";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            
	            formula = "IF("+getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +">"+ getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber
	            			+","+getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber+"-"+ getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber
	            			+",0)";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );

	            formula = "IF( SUM("+getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m2Str ) )+nextRowNumber + ")>"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber
    			+ ",SUM(" +getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m2Str ) )+nextRowNumber + ")-"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber +"-SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber + ")"
    			+",0)";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            
	            formula = "IF( SUM("+getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m3Str ) )+nextRowNumber + ")>"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber
    			+ ",SUM(" +getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m3Str ) )+nextRowNumber + ")-"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber +"-SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( b2Str ) )+nextRowNumber + ")"
    			+",0)";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            
	            formula = "IF( SUM("+getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m4Str ) )+nextRowNumber + ")>"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber
    			+ ",SUM(" +getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m4Str ) )+nextRowNumber + ")-"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber +"-SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( b3Str ) )+nextRowNumber + ")"
    			+",0)";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            
	            formula = "IF( SUM("+getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m5Str ) )+nextRowNumber + ")>"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber
    			+ ",SUM(" +getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m5Str ) )+nextRowNumber + ")-"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber +"-SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( b4Str ) )+nextRowNumber + ")"
    			+",0)";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            
	            formula = "IF( SUM("+getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m6Str ) )+nextRowNumber + ")>"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber
    			+ ",SUM(" +getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m6Str ) )+nextRowNumber + ")-"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber +"-SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( b5Str ) )+nextRowNumber + ")"
    			+",0)";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            
	            formula = "IF( SUM("+getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m7Str ) )+nextRowNumber + ")>"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber
    			+ ",SUM(" +getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m7Str ) )+nextRowNumber + ")-"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber +"-SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( b6Str ) )+nextRowNumber + ")"
    			+",0)";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            
	            formula = "IF( SUM("+getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m8Str ) )+nextRowNumber + ")>"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber
    			+ ",SUM(" +getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m8Str ) )+nextRowNumber + ")-"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber +"-SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( b7Str ) )+nextRowNumber + ")"
    			+",0)";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            
	            formula = "IF( SUM("+getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m9Str ) )+nextRowNumber + ")>"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber
    			+ ",SUM(" +getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m9Str ) )+nextRowNumber + ")-"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber +"-SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( b8Str ) )+nextRowNumber + ")"
    			+",0)";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            
	            formula = "IF( SUM("+getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m10Str ) )+nextRowNumber + ")>"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber
    			+ ",SUM(" +getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m10Str ) )+nextRowNumber + ")-"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber +"-SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( b9Str ) )+nextRowNumber + ")"
    			+",0)";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            
	            formula = "IF( SUM("+getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m11Str ) )+nextRowNumber + ")>"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber
    			+ ",SUM(" +getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m11Str ) )+nextRowNumber + ")-"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber +"-SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( b10Str ) )+nextRowNumber + ")"
    			+",0)";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            
	            formula = "IF( SUM("+getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m12Str ) )+nextRowNumber + ")>"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber
    			+ ",SUM(" +getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m12Str ) )+nextRowNumber + ")-"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber +"-SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( b11Str ) )+nextRowNumber + ")"
    			+",0)";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getFabCycleTime(), productStyle, Cell.CELL_TYPE_NUMERIC  );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getSortCycleTime(), productStyle, Cell.CELL_TYPE_NUMERIC  );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getAssemblyCycleTime(), productStyle, Cell.CELL_TYPE_NUMERIC  );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getTestCycleTime(), productStyle, Cell.CELL_TYPE_NUMERIC  );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getEolCycleTime(), productStyle, Cell.CELL_TYPE_NUMERIC  );

	            formula = "SUM(" + getAlphaforIdx( columnList.indexOf( fabCycleTime ) )+nextRowNumber + "+" 
	            		  + getAlphaforIdx( columnList.indexOf( sortCycleTime ) )+nextRowNumber + "+" 
	            		  + getAlphaforIdx( columnList.indexOf( assemblyCycleTime ) )+nextRowNumber + "+" 
	            		  + getAlphaforIdx( columnList.indexOf( testCycleTime ) )+nextRowNumber + "+" 
	            		  + getAlphaforIdx( columnList.indexOf( eolCycleTime ) )+nextRowNumber+")/7";
	            
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            /*
	            //W1STR
	            formula = "(SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber+":";
	            int cycleTime = (waferStartData.getFabCycleTime() + waferStartData.getSortCycleTime() + waferStartData.getAssemblyCycleTime() + waferStartData.getTestCycleTime() + waferStartData.getEolCycleTime())/7;
	            int fullFilledCycleTime = 0; 
	            boolean fullFilled = false;
	            int i = 0;
	            while ( !fullFilled )
	            {
	            	fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];
	            	if( fullFilledCycleTime >= cycleTime )
	            	{
	            		fullFilled = true;
	            	}
	            	else
	            	{
	            		i++;
	            	}
	            }
	            	            
	            if ( fullFilledCycleTime > cycleTime )
	            {
	            	formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i - 1] ) )+nextRowNumber+") + (("
	            				+ getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+nextRowNumber + "/"
	            				+ getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+2 +")*"
	            				+ ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))/"
	            				+ getAlphaforIdx( columnList.indexOf( ndpwStr ) )+nextRowNumber;
	            }
	            else
	            {
	            	formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+nextRowNumber+"))/"
	            				+ getAlphaforIdx( columnList.indexOf( ndpwStr ) )+nextRowNumber;
	            }
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            
	            //W2STR
	            formula = "((SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber+":";
	            cycleTime = cycleTime + cycleTimes[1];
	            fullFilledCycleTime = 0; 
	            fullFilled = false;
	            i = 0;
	            while ( !fullFilled )
	            {
	            	fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];
	            	if( fullFilledCycleTime >= cycleTime )
	            	{
	            		fullFilled = true;
	            	}
	            	else
	            	{
	            		i++;
	            	}
	            }
	            	            
	            if ( fullFilledCycleTime > cycleTime )
	            {
	            	formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i - 1] ) )+nextRowNumber+") + (("
	            				+ getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+nextRowNumber + "/"
	            				+ getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+2 +")*"
	            				+ ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))/"
	            				+ getAlphaforIdx( columnList.indexOf( ndpwStr ) )+nextRowNumber+")-SUM("
	            				+ getAlphaforIdx( columnList.indexOf( w1Str ) )+nextRowNumber+":"
	            				+ getAlphaforIdx( columnList.indexOf( w1Str ) )+nextRowNumber+")";
	            }
	            else
	            {
	            	formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+nextRowNumber+"))/"
	            				+ getAlphaforIdx( columnList.indexOf( ndpwStr ) )+nextRowNumber + ")-SUM("
	            				+ getAlphaforIdx( columnList.indexOf( w1Str ) )+nextRowNumber+":"
	            				+ getAlphaforIdx( columnList.indexOf( w1Str ) )+nextRowNumber+")";
	            }
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            
	            //W3STR
	            formula = "((SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber+":";
	            cycleTime = cycleTime + cycleTimes[2];
	            fullFilledCycleTime = 0; 
	            fullFilled = false;
	            i = 0;
	            while ( !fullFilled )
	            {
	            	fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];
	            	if( fullFilledCycleTime >= cycleTime )
	            	{
	            		fullFilled = true;
	            	}
	            	else
	            	{
	            		i++;
	            	}
	            }
	            	            
	            if ( fullFilledCycleTime > cycleTime )
	            {
	            	formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i - 1] ) )+nextRowNumber+") + (("
	            				+ getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+nextRowNumber + "/"
	            				+ getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+2 +")*"
	            				+ ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))/"
	            				+ getAlphaforIdx( columnList.indexOf( ndpwStr ) )+nextRowNumber+")-SUM("
	            				+ getAlphaforIdx( columnList.indexOf( w1Str ) )+nextRowNumber+":"
	            				+ getAlphaforIdx( columnList.indexOf( w2Str ) )+nextRowNumber+")";
	            }
	            else
	            {
	            	formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+nextRowNumber+"))/"
	            				+ getAlphaforIdx( columnList.indexOf( ndpwStr ) )+nextRowNumber + ")-SUM("
	            				+ getAlphaforIdx( columnList.indexOf( w1Str ) )+nextRowNumber+":"
	            				+ getAlphaforIdx( columnList.indexOf( w2Str ) )+nextRowNumber+")";
	            }
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            
	            //W4STR
	            formula = "((SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber+":";
	            cycleTime = cycleTime + cycleTimes[3];
	            fullFilledCycleTime = 0; 
	            fullFilled = false;
	            i = 0;
	            while ( !fullFilled )
	            {
	            	fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];
	            	if( fullFilledCycleTime >= cycleTime )
	            	{
	            		fullFilled = true;
	            	}
	            	else
	            	{
	            		i++;
	            	}
	            }
	            	            
	            if ( fullFilledCycleTime > cycleTime )
	            {
	            	formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i - 1] ) )+nextRowNumber+") + (("
	            				+ getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+nextRowNumber + "/"
	            				+ getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+2 +")*"
	            				+ ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))/"
	            				+ getAlphaforIdx( columnList.indexOf( ndpwStr ) )+nextRowNumber+")-SUM("
	            				+ getAlphaforIdx( columnList.indexOf( w1Str ) )+nextRowNumber+":"
	            				+ getAlphaforIdx( columnList.indexOf( w3Str ) )+nextRowNumber+")";
	            }
	            else
	            {
	            	formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+nextRowNumber+"))/"
	            				+ getAlphaforIdx( columnList.indexOf( ndpwStr ) )+nextRowNumber + ")-SUM("
	            				+ getAlphaforIdx( columnList.indexOf( w1Str ) )+nextRowNumber+":"
	            				+ getAlphaforIdx( columnList.indexOf( w3Str ) )+nextRowNumber+")";
	            }
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	           
	            //W5STR
	            formula = "((SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber+":";
	            cycleTime = cycleTime + cycleTimes[4];
	            fullFilledCycleTime = 0; 
	            fullFilled = false;
	            i = 0;
	            while ( !fullFilled )
	            {
	            	fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];
	            	if( fullFilledCycleTime >= cycleTime )
	            	{
	            		fullFilled = true;
	            	}
	            	else
	            	{
	            		i++;
	            	}
	            }
	            	            
	            if ( fullFilledCycleTime > cycleTime )
	            {
	            	formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i - 1] ) )+nextRowNumber+") + (("
	            				+ getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+nextRowNumber + "/"
	            				+ getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+2 +")*"
	            				+ ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))/"
	            				+ getAlphaforIdx( columnList.indexOf( ndpwStr ) )+nextRowNumber+")-SUM("
	            				+ getAlphaforIdx( columnList.indexOf( w1Str ) )+nextRowNumber+":"
	            				+ getAlphaforIdx( columnList.indexOf( w4Str ) )+nextRowNumber+")";
	            }
	            else
	            {
	            	formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+nextRowNumber+"))/"
	            				+ getAlphaforIdx( columnList.indexOf( ndpwStr ) )+nextRowNumber + ")-SUM("
	            				+ getAlphaforIdx( columnList.indexOf( w1Str ) )+nextRowNumber+":"
	            				+ getAlphaforIdx( columnList.indexOf( w4Str ) )+nextRowNumber+")";
	            }
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	                      
	            //W6STR
	            formula = "((SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber+":";
	            cycleTime = cycleTime + cycleTimes[5];
	            fullFilledCycleTime = 0; 
	            fullFilled = false;
	            i = 0;
	            while ( !fullFilled && i < 12 )
	            {
	            	fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];
	            	if( fullFilledCycleTime >= cycleTime )
	            	{
	            		fullFilled = true;
	            	}
	            	else
	            	{
	            		i++;
	            	}
	            }
	            	            
	            if ( fullFilledCycleTime > cycleTime )
	            {
	            	formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i - 1] ) )+nextRowNumber+") + (("
	            				+ getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+nextRowNumber + "/"
	            				+ getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+2 +")*"
	            				+ ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))/"
	            				+ getAlphaforIdx( columnList.indexOf( ndpwStr ) )+nextRowNumber+")-SUM("
	            				+ getAlphaforIdx( columnList.indexOf( w1Str ) )+nextRowNumber+":"
	            				+ getAlphaforIdx( columnList.indexOf( w5Str ) )+nextRowNumber+")";
	            }
	            else
	            {
	            	formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+nextRowNumber+"))/"
	            				+ getAlphaforIdx( columnList.indexOf( ndpwStr ) )+nextRowNumber + ")-SUM("
	            				+ getAlphaforIdx( columnList.indexOf( w1Str ) )+nextRowNumber+":"
	            				+ getAlphaforIdx( columnList.indexOf( w5Str ) )+nextRowNumber+")";
	            }
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	           
	            //W6STR
	            formula = "((SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber+":";
	            cycleTime = cycleTime + cycleTimes[6];
	            fullFilledCycleTime = 0; 
	            fullFilled = false;
	            i = 0;
	            while ( !fullFilled && i < 12 )
	            {
	            	fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];
	            	if( fullFilledCycleTime >= cycleTime )
	            	{
	            		fullFilled = true;
	            	}
	            	else
	            	{
	            		i++;
	            	}
	            }
	            	            
	            if ( fullFilledCycleTime > cycleTime )
	            {
	            	formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i - 1] ) )+nextRowNumber+") + (("
	            				+ getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+nextRowNumber + "/"
	            				+ getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+2 +")*"
	            				+ ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))/"
	            				+ getAlphaforIdx( columnList.indexOf( ndpwStr ) )+nextRowNumber+")-SUM("
	            				+ getAlphaforIdx( columnList.indexOf( w1Str ) )+nextRowNumber+":"
	            				+ getAlphaforIdx( columnList.indexOf( w6Str ) )+nextRowNumber+")";
	            }
	            else
	            {
	            	formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+nextRowNumber+"))/"
	            				+ getAlphaforIdx( columnList.indexOf( ndpwStr ) )+nextRowNumber + ")-SUM("
	            				+ getAlphaforIdx( columnList.indexOf( w1Str ) )+nextRowNumber+":"
	            				+ getAlphaforIdx( columnList.indexOf( w6Str ) )+nextRowNumber+")";
	            }
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            
	            //W7STR
	            formula = "((SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber+":";
	            cycleTime = cycleTime + cycleTimes[7];
	            fullFilledCycleTime = 0; 
	            fullFilled = false;
	            i = 0;
	            while ( !fullFilled && i < 12 )
	            {
	            	fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];
	            	if( fullFilledCycleTime >= cycleTime )
	            	{
	            		fullFilled = true;
	            	}
	            	else
	            	{
	            		i++;
	            	}
	            }
	            
	            if ( fullFilledCycleTime > cycleTime )
	            {
	            	
	            	formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i - 1] ) )+nextRowNumber+") + (("
	            				+ getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+nextRowNumber + "/"
	            				+ getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+2 +")*"
	            				+ ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))/"
	            				+ getAlphaforIdx( columnList.indexOf( ndpwStr ) )+nextRowNumber+")-SUM("
	            				+ getAlphaforIdx( columnList.indexOf( w1Str ) )+nextRowNumber+":"
	            				+ getAlphaforIdx( columnList.indexOf( w7Str ) )+nextRowNumber+")";
	            }
	            else
	            {
	            	if( i < 12 )// Need to remove later...........
	            	{
	            		
	            		formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+nextRowNumber+"))/"
	            				+ getAlphaforIdx( columnList.indexOf( ndpwStr ) )+nextRowNumber + ")-SUM("
	            				+ getAlphaforIdx( columnList.indexOf( w1Str ) )+nextRowNumber+":"
	            				+ getAlphaforIdx( columnList.indexOf( w7Str ) )+nextRowNumber+")";
	            	}
	            	else
	            	{
	            		formula = "";
	            	}
	            }
	            
	            if( formula.length() > 1 )
	            {
	            	setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            }
	            else
	            {
		            setCellValue( row, (short)nextColumnIdx++, 0, productStyle, Cell.CELL_TYPE_NUMERIC  );
	            }
	            
	            //W8STR
	            formula = "((SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber+":";
	            cycleTime = cycleTime + cycleTimes[8];
	            fullFilledCycleTime = 0; 
	            fullFilled = false;
	            i = 0;
	            while ( !fullFilled && i < 12 )
	            {
	            	fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];
	            	if( fullFilledCycleTime >= cycleTime )
	            	{
	            		fullFilled = true;
	            	}
	            	else
	            	{
	            		i++;
	            	}
	            }
	            
	            if( i == 12 ) i = 11;
	            	            
	            if ( fullFilledCycleTime > cycleTime )
	            {
	            	formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i - 1] ) )+nextRowNumber+") + (("
	            				+ getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+nextRowNumber + "/"
	            				+ getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+2 +")*"
	            				+ ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))/"
	            				+ getAlphaforIdx( columnList.indexOf( ndpwStr ) )+nextRowNumber+")-SUM("
	            				+ getAlphaforIdx( columnList.indexOf( w1Str ) )+nextRowNumber+":"
	            				+ getAlphaforIdx( columnList.indexOf( w8Str ) )+nextRowNumber+")";
	            }
	            else
	            {
	            	formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+nextRowNumber+"))/"
	            				+ getAlphaforIdx( columnList.indexOf( ndpwStr ) )+nextRowNumber + ")-SUM("
	            				+ getAlphaforIdx( columnList.indexOf( w1Str ) )+nextRowNumber+":"
	            				+ getAlphaforIdx( columnList.indexOf( w8Str ) )+nextRowNumber+")";
	            }
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            
	            
	            //W9STR
	            formula = "((SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber+":";
	            cycleTime = cycleTime + cycleTimes[9];
	            fullFilledCycleTime = 0; 
	            fullFilled = false;
	            i = 0;
	            while ( !fullFilled && i < 12 )
	            {
	            	fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];
	            	if( fullFilledCycleTime >= cycleTime )
	            	{
	            		fullFilled = true;
	            	}
	            	else
	            	{
	            		i++;
	            	}
	            }
	            
	            if( i == 12 ) i = 11;
	            
	            if ( fullFilledCycleTime > cycleTime )
	            {
	            	formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i - 1] ) )+nextRowNumber+") + (("
	            				+ getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+nextRowNumber + "/"
	            				+ getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+2 +")*"
	            				+ ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))/"
	            				+ getAlphaforIdx( columnList.indexOf( ndpwStr ) )+nextRowNumber+")-SUM("
	            				+ getAlphaforIdx( columnList.indexOf( w1Str ) )+nextRowNumber+":"
	            				+ getAlphaforIdx( columnList.indexOf( w9Str ) )+nextRowNumber+")";
	            }
	            else
	            {
	            	formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+nextRowNumber+"))/"
	            				+ getAlphaforIdx( columnList.indexOf( ndpwStr ) )+nextRowNumber + ")-SUM("
	            				+ getAlphaforIdx( columnList.indexOf( w1Str ) )+nextRowNumber+":"
	            				+ getAlphaforIdx( columnList.indexOf( w9Str ) )+nextRowNumber+")";
	            }
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );    
	            */ 
	            //nextColumnIdx++;
	            //nextColumnIdx++;
	            
	            String subFormula = "";
	            String nextFormula = "";

                if( prevFabPart != null && prevFabPart.length() > 1 && !prevFabPart.equalsIgnoreCase( waferStartData.getFabPartNumber() ) )
                {
                    subFormula = "(";
                    for( int i = mergerIdx; i <= (nextRowNumber-1); i++ )
                    {
                        subFormula = subFormula + getAlphaforIdx( columnList.indexOf( b1Str ) )+i +"*"+ getAlphaforIdx( columnList.indexOf( diePerPackageQtyStr ) )+i + " +";
                    }
                    subFormula = subFormula.substring(0, (subFormula.length() - 1)) + ")";


                    formula = "IF("+ subFormula +">"+ getAlphaforIdx( columnList.indexOf( backEndDieStr ) )+mergerIdx
                    +","+ subFormula +"-"+ getAlphaforIdx( columnList.indexOf( backEndDieStr ) )+mergerIdx
                    +",0)";

                    //formula = "SUM("+ getAlphaforIdx( columnList.indexOf( b1Str ) )+mergerIdx +":"+getAlphaforIdx( columnList.indexOf( b1Str ) )+(nextRowNumber -1) +")";
                    setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w1Str), nextRowNumber- 2, (short)columnList.indexOf(w1Str) );

                    subFormula = "(";
                    for( int i = mergerIdx; i <= (nextRowNumber-1); i++ )
                    {
                        subFormula = subFormula + "SUM("+ getAlphaforIdx( columnList.indexOf( b1Str ) )+i +":"+getAlphaforIdx( columnList.indexOf( b2Str ) )+i +")*" + getAlphaforIdx( columnList.indexOf( diePerPackageQtyStr ) )+i + " +";
                    }
                    subFormula = subFormula.substring(0, (subFormula.length() - 1)) + ")";

                    if( mergerIdx == (nextRowNumber-1) )
                    {
                        nextFormula = "SUM("+ getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx +":"+getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx +")";
                    }
                    else
                    {
                        nextFormula = "(";
                        for( int i = mergerIdx; i <= (nextRowNumber-1); i++ )
                        {
                            nextFormula = nextFormula + "SUM("+ getAlphaforIdx( columnList.indexOf( w1Str ) )+i +":"+getAlphaforIdx( columnList.indexOf( w1Str ) )+i +")-";
                        }
                        nextFormula = nextFormula.substring(0, (nextFormula.length() -1 )) + ")";
                    }
                    //subFormula = "(SUM("+ getAlphaforIdx( columnList.indexOf( b1Str ) )+mergerIdx +":"+getAlphaforIdx( columnList.indexOf( b2Str ) )+mergerIdx +")+SUM("+ getAlphaforIdx( columnList.indexOf( b1Str ) )+(nextRowNumber -1) +":"+getAlphaforIdx( columnList.indexOf( b2Str ) )+(nextRowNumber -1) +"))";

                    formula = "IF( "+ subFormula +" >"+getAlphaforIdx( columnList.indexOf( backEndDieStr ) )+mergerIdx
                    + ","+subFormula+"-"+getAlphaforIdx( columnList.indexOf( backEndDieStr ) )+mergerIdx +"-"+nextFormula+",0)";

                    //formula = "SUM("+ getAlphaforIdx( columnList.indexOf( b2Str ) )+mergerIdx +":"+getAlphaforIdx( columnList.indexOf( b2Str ) )+(nextRowNumber -1) +")";
                    setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w2Str), nextRowNumber- 2, (short)columnList.indexOf(w2Str) );


                    subFormula = "(";
                    for( int i = mergerIdx; i <= (nextRowNumber-1); i++ )
                    {
                        subFormula = subFormula + "SUM("+ getAlphaforIdx( columnList.indexOf( b1Str ) )+i +":"+getAlphaforIdx( columnList.indexOf( b3Str ) )+i +")*" + getAlphaforIdx( columnList.indexOf( diePerPackageQtyStr ) )+i + " +";
                    }
                    subFormula = subFormula.substring(0, (subFormula.length() - 1)) + ")";

                    if( mergerIdx == (nextRowNumber-1) )
                    {
                        nextFormula = "SUM("+ getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx +":"+getAlphaforIdx( columnList.indexOf( w2Str ) )+mergerIdx +")";
                    }
                    else
                    {
                        nextFormula = "(";
                        for( int i = mergerIdx; i <= (nextRowNumber-1); i++ )
                        {
                            nextFormula = nextFormula + "SUM("+ getAlphaforIdx( columnList.indexOf( w1Str ) )+i +":"+getAlphaforIdx( columnList.indexOf( w2Str ) )+i +")-";
                        }
                        nextFormula = nextFormula.substring(0, (nextFormula.length() -1 )) + ")";
                    }

                    formula = "IF( "+ subFormula +" >"+getAlphaforIdx( columnList.indexOf( backEndDieStr ) )+mergerIdx
                    + ","+subFormula+"-"+getAlphaforIdx( columnList.indexOf( backEndDieStr ) )+mergerIdx +"-"+nextFormula+",0)";
                    //formula = "SUM("+ getAlphaforIdx( columnList.indexOf( b3Str ) )+mergerIdx +":"+getAlphaforIdx( columnList.indexOf( b3Str ) )+(nextRowNumber -1) +")";
                    setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w3Str), nextRowNumber- 2, (short)columnList.indexOf(w3Str) );


                    subFormula = "(";
                    for( int i = mergerIdx; i <= (nextRowNumber-1); i++ )
                    {
                        subFormula = subFormula + "SUM("+ getAlphaforIdx( columnList.indexOf( b1Str ) )+i +":"+getAlphaforIdx( columnList.indexOf( b4Str ) )+i +")*" + getAlphaforIdx( columnList.indexOf( diePerPackageQtyStr ) )+i + " +";
                    }
                    subFormula = subFormula.substring(0, (subFormula.length() - 1)) + ")";

                    if( mergerIdx == (nextRowNumber-1) )
                    {
                        nextFormula = "SUM("+ getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx +":"+getAlphaforIdx( columnList.indexOf( w3Str ) )+mergerIdx +")";
                    }
                    else
                    {
                        nextFormula = "(";
                        for( int i = mergerIdx; i <= (nextRowNumber-1); i++ )
                        {
                            nextFormula = nextFormula + "SUM("+ getAlphaforIdx( columnList.indexOf( w1Str ) )+i +":"+getAlphaforIdx( columnList.indexOf( w3Str ) )+i +")-";
                        }
                        nextFormula = nextFormula.substring(0, (nextFormula.length() -1 )) + ")";
                    }

                    formula = "IF( "+ subFormula +" >"+getAlphaforIdx( columnList.indexOf( backEndDieStr ) )+mergerIdx
                    + ","+subFormula+"-"+getAlphaforIdx( columnList.indexOf( backEndDieStr ) )+mergerIdx +"-"+nextFormula+",0)";
                    //formula = "SUM("+ getAlphaforIdx( columnList.indexOf( b4Str ) )+mergerIdx +":"+getAlphaforIdx( columnList.indexOf( b4Str ) )+(nextRowNumber -1) +")";
                    setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w4Str), nextRowNumber- 2, (short)columnList.indexOf(w4Str) );

                    subFormula = "(";
                    for( int i = mergerIdx; i <= (nextRowNumber-1); i++ )
                    {
                        subFormula = subFormula + "SUM("+ getAlphaforIdx( columnList.indexOf( b1Str ) )+i +":"+getAlphaforIdx( columnList.indexOf( b5Str ) )+i +")*" + getAlphaforIdx( columnList.indexOf( diePerPackageQtyStr ) )+i + " +";
                    }
                    subFormula = subFormula.substring(0, (subFormula.length() - 1)) + ")";

                    if( mergerIdx == (nextRowNumber-1) )
                    {
                        nextFormula = "SUM("+ getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx +":"+getAlphaforIdx( columnList.indexOf( w4Str ) )+mergerIdx +")";
                    }
                    else
                    {
                        nextFormula = "(";
                        for( int i = mergerIdx; i <= (nextRowNumber-1); i++ )
                        {
                            nextFormula = nextFormula + "SUM("+ getAlphaforIdx( columnList.indexOf( w1Str ) )+i +":"+getAlphaforIdx( columnList.indexOf( w4Str ) )+i +")-";
                        }
                        nextFormula = nextFormula.substring(0, (nextFormula.length() -1 )) + ")";
                    }

                    formula = "IF( "+ subFormula +" >"+getAlphaforIdx( columnList.indexOf( backEndDieStr ) )+mergerIdx
                    + ","+subFormula+"-"+getAlphaforIdx( columnList.indexOf( backEndDieStr ) )+mergerIdx +"-"+nextFormula+",0)";
                    //formula = "SUM("+ getAlphaforIdx( columnList.indexOf( b5Str ) )+mergerIdx +":"+getAlphaforIdx( columnList.indexOf( b5Str ) )+(nextRowNumber -1) +")";
                    setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w5Str), nextRowNumber- 2, (short)columnList.indexOf(w5Str) );

                    subFormula = "(";
                    for( int i = mergerIdx; i <= (nextRowNumber-1); i++ )
                    {
                        subFormula = subFormula + "SUM("+ getAlphaforIdx( columnList.indexOf( b1Str ) )+i +":"+getAlphaforIdx( columnList.indexOf( b6Str ) )+i +")*" + getAlphaforIdx( columnList.indexOf( diePerPackageQtyStr ) )+i + " +";
                    }
                    subFormula = subFormula.substring(0, (subFormula.length() - 1)) + ")";

                    if( mergerIdx == (nextRowNumber-1) )
                    {
                        nextFormula = "SUM("+ getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx +":"+getAlphaforIdx( columnList.indexOf( w5Str ) )+mergerIdx +")";
                    }
                    else
                    {
                        nextFormula = "(";
                        for( int i = mergerIdx; i <= (nextRowNumber-1); i++ )
                        {
                            nextFormula = nextFormula + "SUM("+ getAlphaforIdx( columnList.indexOf( w1Str ) )+i +":"+getAlphaforIdx( columnList.indexOf( w5Str ) )+i +")-";
                        }
                        nextFormula = nextFormula.substring(0, (nextFormula.length() -1 )) + ")";
                    }

                    formula = "IF( "+ subFormula +" >"+getAlphaforIdx( columnList.indexOf( backEndDieStr ) )+mergerIdx
                    + ","+subFormula+"-"+getAlphaforIdx( columnList.indexOf( backEndDieStr ) )+mergerIdx +"-"+nextFormula+",0)";

                    //formula = "SUM("+ getAlphaforIdx( columnList.indexOf( b6Str ) )+mergerIdx +":"+getAlphaforIdx( columnList.indexOf( b6Str ) )+(nextRowNumber -1) +")";
                    setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w6Str), nextRowNumber- 2, (short)columnList.indexOf(w6Str) );


                    subFormula = "(";
                    for( int i = mergerIdx; i <= (nextRowNumber-1); i++ )
                    {
                        subFormula = subFormula + "SUM("+ getAlphaforIdx( columnList.indexOf( b1Str ) )+i +":"+getAlphaforIdx( columnList.indexOf( b7Str ) )+i +")*" + getAlphaforIdx( columnList.indexOf( diePerPackageQtyStr ) )+i + " +";
                    }
                    subFormula = subFormula.substring(0, (subFormula.length() - 1)) + ")";

                    if( mergerIdx == (nextRowNumber-1) )
                    {
                        nextFormula = "SUM("+ getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx +":"+getAlphaforIdx( columnList.indexOf( w6Str ) )+mergerIdx +")";
                    }
                    else
                    {
                        nextFormula = "(";
                        for( int i = mergerIdx; i <= (nextRowNumber-1); i++ )
                        {
                            nextFormula = nextFormula + "SUM("+ getAlphaforIdx( columnList.indexOf( w1Str ) )+i +":"+getAlphaforIdx( columnList.indexOf( w6Str ) )+i +")-";
                        }
                        nextFormula = nextFormula.substring(0, (nextFormula.length() -1 )) + ")";
                    }

                    formula = "IF( "+ subFormula +" >"+getAlphaforIdx( columnList.indexOf( backEndDieStr ) )+mergerIdx
                    + ","+subFormula+"-"+getAlphaforIdx( columnList.indexOf( backEndDieStr ) )+mergerIdx +"-"+nextFormula+",0)";
                    //formula = "SUM("+ getAlphaforIdx( columnList.indexOf( b7Str ) )+mergerIdx +":"+getAlphaforIdx( columnList.indexOf( b7Str ) )+(nextRowNumber -1) +")";
                    setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w7Str), nextRowNumber- 2, (short)columnList.indexOf(w7Str) );

                    subFormula = "(";
                    for( int i = mergerIdx; i <= (nextRowNumber-1); i++ )
                    {
                        subFormula = subFormula + "SUM("+ getAlphaforIdx( columnList.indexOf( b1Str ) )+i +":"+getAlphaforIdx( columnList.indexOf( b8Str ) )+i +")*" + getAlphaforIdx( columnList.indexOf( diePerPackageQtyStr ) )+i + " +";
                    }
                    subFormula = subFormula.substring(0, (subFormula.length() - 1)) + ")";

                    if( mergerIdx == (nextRowNumber-1) )
                    {
                        nextFormula = "SUM("+ getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx +":"+getAlphaforIdx( columnList.indexOf( w7Str ) )+mergerIdx +")";
                    }
                    else
                    {
                        nextFormula = "(";
                        for( int i = mergerIdx; i <= (nextRowNumber-1); i++ )
                        {
                            nextFormula = nextFormula + "SUM("+ getAlphaforIdx( columnList.indexOf( w1Str ) )+i +":"+getAlphaforIdx( columnList.indexOf( w7Str ) )+i +")-";
                        }
                        nextFormula = nextFormula.substring(0, (nextFormula.length() -1 )) + ")";
                    }

                    formula = "IF( "+ subFormula +" >"+getAlphaforIdx( columnList.indexOf( backEndDieStr ) )+mergerIdx
                    + ","+subFormula+"-"+getAlphaforIdx( columnList.indexOf( backEndDieStr ) )+mergerIdx +"-"+nextFormula+",0)";

                    //formula = "SUM("+ getAlphaforIdx( columnList.indexOf( b8Str ) )+mergerIdx +":"+getAlphaforIdx( columnList.indexOf( b8Str ) )+(nextRowNumber -1) +")";
                    setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w8Str), nextRowNumber- 2, (short)columnList.indexOf(w8Str) );

                    subFormula = "(";
                    for( int i = mergerIdx; i <= (nextRowNumber-1); i++ )
                    {
                        subFormula = subFormula + "SUM("+ getAlphaforIdx( columnList.indexOf( b1Str ) )+i +":"+getAlphaforIdx( columnList.indexOf( b9Str ) )+i +")*" + getAlphaforIdx( columnList.indexOf( diePerPackageQtyStr ) )+i + " +";
                    }
                    subFormula = subFormula.substring(0, (subFormula.length() - 1)) + ")";

                    if( mergerIdx == (nextRowNumber-1) )
                    {
                        nextFormula = "SUM("+ getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx +":"+getAlphaforIdx( columnList.indexOf( w8Str ) )+mergerIdx +")";
                    }
                    else
                    {
                        nextFormula = "(";
                        for( int i = mergerIdx; i <= (nextRowNumber-1); i++ )
                        {
                            nextFormula = nextFormula + "SUM("+ getAlphaforIdx( columnList.indexOf( w1Str ) )+i +":"+getAlphaforIdx( columnList.indexOf( w8Str ) )+i +")-";
                        }
                        nextFormula = nextFormula.substring(0, (nextFormula.length() -1 )) + ")";
                    }

                    formula = "IF( "+ subFormula +" >"+getAlphaforIdx( columnList.indexOf( backEndDieStr ) )+mergerIdx
                    + ","+subFormula+"-"+getAlphaforIdx( columnList.indexOf( backEndDieStr ) )+mergerIdx +"-"+nextFormula+",0)";

                    //formula = "SUM("+ getAlphaforIdx( columnList.indexOf( b9Str ) )+mergerIdx +":"+getAlphaforIdx( columnList.indexOf( b9Str ) )+(nextRowNumber -1) +")";
                    setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w9Str), nextRowNumber- 2, (short)columnList.indexOf(w9Str) );

                    subFormula = "(";
                    for( int i = mergerIdx; i <= (nextRowNumber-1); i++ )
                    {
                        subFormula = subFormula + "SUM("+ getAlphaforIdx( columnList.indexOf( b1Str ) )+i +":"+getAlphaforIdx( columnList.indexOf( b10Str ) )+i +")*" + getAlphaforIdx( columnList.indexOf( diePerPackageQtyStr ) )+i + " +";
                    }
                    subFormula = subFormula.substring(0, (subFormula.length() - 1)) + ")";

                    if( mergerIdx == (nextRowNumber-1) )
                    {
                        nextFormula = "SUM("+ getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx +":"+getAlphaforIdx( columnList.indexOf( w9Str ) )+mergerIdx +")";
                    }
                    else
                    {
                        nextFormula = "(";
                        for( int i = mergerIdx; i <= (nextRowNumber-1); i++ )
                        {
                            nextFormula = nextFormula + "SUM("+ getAlphaforIdx( columnList.indexOf( w1Str ) )+i +":"+getAlphaforIdx( columnList.indexOf( w9Str ) )+i +")-";
                        }
                        nextFormula = nextFormula.substring(0, (nextFormula.length() -1 )) + ")";
                    }

                    formula = "IF( "+ subFormula +" >"+getAlphaforIdx( columnList.indexOf( backEndDieStr ) )+mergerIdx
                    + ","+subFormula+"-"+getAlphaforIdx( columnList.indexOf( backEndDieStr ) )+mergerIdx +"-"+nextFormula+",0)";
                    //formula = "SUM("+ getAlphaforIdx( columnList.indexOf( b10Str ) )+mergerIdx +":"+getAlphaforIdx( columnList.indexOf( b10Str ) )+(nextRowNumber -1) +")";
                    setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w10Str), nextRowNumber- 2, (short)columnList.indexOf(w10Str) );

                    subFormula = "(";
                    for( int i = mergerIdx; i <= (nextRowNumber-1); i++ )
                    {
                        subFormula = subFormula + "SUM("+ getAlphaforIdx( columnList.indexOf( b1Str ) )+i +":"+getAlphaforIdx( columnList.indexOf( b11Str ) )+i +")*" + getAlphaforIdx( columnList.indexOf( diePerPackageQtyStr ) )+i + " +";
                    }
                    subFormula = subFormula.substring(0, (subFormula.length() - 1)) + ")";

                    if( mergerIdx == (nextRowNumber-1) )
                    {
                        nextFormula = "SUM("+ getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx +":"+getAlphaforIdx( columnList.indexOf( w10Str ) )+mergerIdx +")";
                    }
                    else
                    {
                        nextFormula = "(";
                        for( int i = mergerIdx; i <= (nextRowNumber-1); i++ )
                        {
                            nextFormula = nextFormula + "SUM("+ getAlphaforIdx( columnList.indexOf( w1Str ) )+i +":"+getAlphaforIdx( columnList.indexOf( w10Str ) )+i +")-";
                        }
                        nextFormula = nextFormula.substring(0, (nextFormula.length() -1 )) + ")";
                    }

                    formula = "IF( "+ subFormula +" >"+getAlphaforIdx( columnList.indexOf( backEndDieStr ) )+mergerIdx
                    + ","+subFormula+"-"+getAlphaforIdx( columnList.indexOf( backEndDieStr ) )+mergerIdx +"-"+nextFormula+",0)";
                    //formula = "SUM("+ getAlphaforIdx( columnList.indexOf( b11Str ) )+mergerIdx +":"+getAlphaforIdx( columnList.indexOf( b11Str ) )+(nextRowNumber -1) +")";
                    setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w11Str), nextRowNumber- 2, (short)columnList.indexOf(w11Str) );

                    subFormula = "(";
                    for( int i = mergerIdx; i <= (nextRowNumber-1); i++ )
                    {
                        subFormula = subFormula + "SUM("+ getAlphaforIdx( columnList.indexOf( b1Str ) )+i +":"+getAlphaforIdx( columnList.indexOf( b12Str ) )+i +")*" + getAlphaforIdx( columnList.indexOf( diePerPackageQtyStr ) )+i + " +";
                    }
                    subFormula = subFormula.substring(0, (subFormula.length() - 1)) + ")";

                    if( mergerIdx == (nextRowNumber-1) )
                    {
                        nextFormula = "SUM("+ getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx +":"+getAlphaforIdx( columnList.indexOf( w11Str ) )+mergerIdx +")";
                    }
                    else
                    {
                        nextFormula = "(";
                        for( int i = mergerIdx; i <= (nextRowNumber-1); i++ )
                        {
                            nextFormula = nextFormula + "SUM("+ getAlphaforIdx( columnList.indexOf( w1Str ) )+i +":"+getAlphaforIdx( columnList.indexOf( w11Str ) )+i +")-";
                        }
                        nextFormula = nextFormula.substring(0, (nextFormula.length() -1 )) + ")";
                    }

                    formula = "IF( "+ subFormula +" >"+getAlphaforIdx( columnList.indexOf( backEndDieStr ) )+mergerIdx
                    + ","+subFormula+"-"+getAlphaforIdx( columnList.indexOf( backEndDieStr ) )+mergerIdx +"-"+nextFormula+",0)";
                    //formula = "SUM("+ getAlphaforIdx( columnList.indexOf( b12Str ) )+mergerIdx +":"+getAlphaforIdx( columnList.indexOf( b12Str ) )+(nextRowNumber -1) +")";
                    setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w12Str), nextRowNumber- 2, (short)columnList.indexOf(w12Str) );

                    //P1STR
                    formula = "(SUM("+getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx+":";
                    //int cycleTime = (waferStartData.getFabCycleTime() + waferStartData.getSortCycleTime() + waferStartData.getAssemblyCycleTime() + waferStartData.getTestCycleTime() + waferStartData.getEolCycleTime())/7;
                    int cycleTime = prevCycleTime;
                    int fullFilledCycleTime = 0;
                    boolean fullFilled = false;
                    int i = 0;

                    while ( !fullFilled )
                    {
                        fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];
                        if( fullFilledCycleTime >= cycleTime )
                        {
                            fullFilled = true;
                        }
                        else
                        {
                            i++;
                        }
                    }

                    if ( fullFilledCycleTime > cycleTime )
                    {
                        formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i - 1] ) )+mergerIdx+") + (("
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx + "/"
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+2 +")*"
                                    + ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))/"
                                    + getAlphaforIdx( columnList.indexOf( ndpwStr ) )+mergerIdx;
                    }
                    else
                    {
                        formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx+"))/"
                                    + getAlphaforIdx( columnList.indexOf( ndpwStr ) )+mergerIdx;
                    }

                    //System.out.println("FORMULA:::::" + formula);
                    if( cycleTimes[0] == 0 )
                    {
                        setCellValue( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, 0, productValueStyle, Cell.CELL_TYPE_NUMERIC );
                    }
                    else
                    {
                        setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                    }
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(p1Str), nextRowNumber- 2, (short)columnList.indexOf(p1Str) );

                    //P2STR
                    formula = "((SUM("+getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx+":";
                    cycleTime = cycleTime + cycleTimes[1];
                    fullFilledCycleTime = 0;
                    fullFilled = false;
                    i = 0;
                    while ( !fullFilled )
                    {
                        fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];
                        if( fullFilledCycleTime >= cycleTime )
                        {
                            fullFilled = true;
                        }
                        else
                        {
                            i++;
                        }
                    }

                    if ( fullFilledCycleTime > cycleTime )
                    {
                        formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i - 1] ) )+mergerIdx+") + (("
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx + "/"
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+2 +")*"
                                    + ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))/"
                                    + getAlphaforIdx( columnList.indexOf( ndpwStr ) )+mergerIdx+")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( p1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( p1Str ) )+mergerIdx+")";
                    }
                    else
                    {
                        formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx+"))/"
                                    + getAlphaforIdx( columnList.indexOf( ndpwStr ) )+mergerIdx + ")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( p1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( p1Str ) )+mergerIdx+")";
                    }
                    if( cycleTimes[1] == 0 )
                    {
                        setCellValue( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, 0, productValueStyle, Cell.CELL_TYPE_NUMERIC );
                    }
                    else
                    {
                        setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                    }
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(p2Str), nextRowNumber- 2, (short)columnList.indexOf(p2Str) );

                    //P3STR
                    formula = "((SUM("+getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx+":";
                    cycleTime = cycleTime + cycleTimes[2];
                    fullFilledCycleTime = 0;
                    fullFilled = false;
                    i = 0;
                    while ( !fullFilled )
                    {
                        fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];
                        if( fullFilledCycleTime >= cycleTime )
                        {
                            fullFilled = true;
                        }
                        else
                        {
                            i++;
                        }
                    }

                    if ( fullFilledCycleTime > cycleTime )
                    {
                        formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i - 1] ) )+mergerIdx+") + (("
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx + "/"
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+2 +")*"
                                    + ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))/"
                                    + getAlphaforIdx( columnList.indexOf( ndpwStr ) )+mergerIdx+")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( p1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( p2Str ) )+mergerIdx+")";
                    }
                    else
                    {
                        formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx+"))/"
                                    + getAlphaforIdx( columnList.indexOf( ndpwStr ) )+mergerIdx + ")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( p1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( p2Str ) )+mergerIdx+")";
                    }

                    if( cycleTimes[2] == 0 )
                    {
                        setCellValue( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, 0, productValueStyle, Cell.CELL_TYPE_NUMERIC );
                    }
                    else
                    {
                        setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                    }
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(p3Str), nextRowNumber- 2, (short)columnList.indexOf(p3Str) );

                    //P4STR
                    formula = "((SUM("+getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx+":";
                    cycleTime = cycleTime + cycleTimes[3];
                    fullFilledCycleTime = 0;
                    fullFilled = false;
                    i = 0;
                    while ( !fullFilled )
                    {
                        fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];
                        if( fullFilledCycleTime >= cycleTime )
                        {
                            fullFilled = true;
                        }
                        else
                        {
                            i++;
                        }
                    }

                    if ( fullFilledCycleTime > cycleTime )
                    {
                        formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i - 1] ) )+mergerIdx+") + (("
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx + "/"
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+2 +")*"
                                    + ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))/"
                                    + getAlphaforIdx( columnList.indexOf( ndpwStr ) )+mergerIdx+")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( p1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( p3Str ) )+mergerIdx+")";
                    }
                    else
                    {
                        formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx+"))/"
                                    + getAlphaforIdx( columnList.indexOf( ndpwStr ) )+mergerIdx + ")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( p1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( p3Str ) )+mergerIdx+")";
                    }
                    //System.out.println("formula = " + formula);
                    setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(p4Str), nextRowNumber- 2, (short)columnList.indexOf(p4Str) );

                    //P5STR
                    formula = "((SUM("+getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx+":";
                    cycleTime = cycleTime + cycleTimes[4];
                    fullFilledCycleTime = 0;
                    fullFilled = false;
                    i = 0;
                    while ( !fullFilled )
                    {
                        fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];
                        if( fullFilledCycleTime >= cycleTime )
                        {
                            fullFilled = true;
                        }
                        else
                        {
                            i++;
                        }
                    }

                    if ( fullFilledCycleTime > cycleTime )
                    {
                        formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i - 1] ) )+mergerIdx+") + (("
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx + "/"
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+2 +")*"
                                    + ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))/"
                                    + getAlphaforIdx( columnList.indexOf( ndpwStr ) )+mergerIdx+")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( p1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( p4Str ) )+mergerIdx+")";
                    }
                    else
                    {
                        formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx+"))/"
                                    + getAlphaforIdx( columnList.indexOf( ndpwStr ) )+mergerIdx + ")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( p1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( p4Str ) )+mergerIdx+")";
                    }
                    setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(p5Str), nextRowNumber- 2, (short)columnList.indexOf(p5Str) );

                    //P6STR
                    formula = "((SUM("+getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx+":";
                    cycleTime = cycleTime + cycleTimes[5];
                    fullFilledCycleTime = 0;
                    fullFilled = false;
                    i = 0;
                    while ( !fullFilled && i < 12 )
                    {
                        fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];

                        if( fullFilledCycleTime >= cycleTime )
                        {
                            fullFilled = true;
                        }
                        else
                        {
                            i++;
                        }
                    }

                    if ( fullFilledCycleTime > cycleTime )
                    {
                        formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i - 1] ) )+mergerIdx+") + (("
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx + "/"
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+2 +")*"
                                    + ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))/"
                                    + getAlphaforIdx( columnList.indexOf( ndpwStr ) )+mergerIdx+")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( p1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( p5Str ) )+mergerIdx+")";
                    }
                    else
                    {
                        if ( i < 12 )
                        {
                            formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx+"))/"
                                    + getAlphaforIdx( columnList.indexOf( ndpwStr ) )+mergerIdx + ")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( p1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( p5Str ) )+mergerIdx+")";
                        }
                        else
                        {
                            formula = "";
                        }
                    }
                    if ( formula.length() > 1 )
                    {
                        setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                        mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(p6Str), nextRowNumber- 2, (short)columnList.indexOf(p6Str) );
                    }
                    else
                    {
                        setCellValue( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, 0, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
                        mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(p6Str), nextRowNumber- 2, (short)columnList.indexOf(p6Str) );
                    }

                    //P7STR
                    formula = "((SUM("+getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx+":";
                    cycleTime = cycleTime + cycleTimes[6];
                    fullFilledCycleTime = 0;
                    fullFilled = false;
                    i = 0;
                    while ( !fullFilled && i < 12 )
                    {
                        fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];

                        if( fullFilledCycleTime >= cycleTime )
                        {
                            fullFilled = true;
                        }
                        else
                        {
                            i++;
                        }
                    }

                    if ( fullFilledCycleTime > cycleTime )
                    {
                        formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i - 1] ) )+mergerIdx+") + (("
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx + "/"
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+2 +")*"
                                    + ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))/"
                                    + getAlphaforIdx( columnList.indexOf( ndpwStr ) )+mergerIdx+")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( p1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( p6Str ) )+mergerIdx+")";
                    }
                    else
                    {
                        if ( i < 12 )
                        {
                            formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx+"))/"
                                    + getAlphaforIdx( columnList.indexOf( ndpwStr ) )+mergerIdx + ")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( p1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( p6Str ) )+mergerIdx+")";
                        }
                        else
                        {
                            formula = "";
                        }
                    }
                    if ( formula.length() > 1 )
                    {
                        setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                        mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(p7Str), nextRowNumber- 2, (short)columnList.indexOf(p7Str) );
                    }
                    else
                    {
                        setCellValue( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, 0, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
                        mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(p7Str), nextRowNumber- 2, (short)columnList.indexOf(p7Str) );
                    }

                    //P8STR
                    formula = "((SUM("+getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx+":";
                    cycleTime = cycleTime + cycleTimes[7];
                    fullFilledCycleTime = 0;
                    fullFilled = false;
                    i = 0;
                    while ( !fullFilled && i < 12 )
                    {
                        //System.out.println("fullFilledCycleTime " + fullFilledCycleTime + "		" + cycleTimes[i] + "		" + cycleTime + "		" + i );
                        fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];
                        if( fullFilledCycleTime >= cycleTime )
                        {
                            fullFilled = true;
                        }
                        else
                        {
                            i++;
                        }
                    }

                    if ( fullFilledCycleTime > cycleTime )
                    {

                        formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i - 1] ) )+mergerIdx+") + (("
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx + "/"
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+2 +")*"
                                    + ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))/"
                                    + getAlphaforIdx( columnList.indexOf( ndpwStr ) )+mergerIdx+")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( p1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( p7Str ) )+mergerIdx+")";
                    }
                    else
                    {
                        if( i < 12 )// Need to remove later...........
                        {

                            formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx+"))/"
                                    + getAlphaforIdx( columnList.indexOf( ndpwStr ) )+mergerIdx + ")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( p1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( p7Str ) )+mergerIdx+")";
                        }
                        else
                        {
                            formula = "";
                        }
                    }

                    if( formula.length() > 1 )
                    {
                        setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                        mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(p8Str), nextRowNumber- 2, (short)columnList.indexOf(p8Str) );
                    }
                    else
                    {
                        setCellValue( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, 0, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
                        mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(p8Str), nextRowNumber- 2, (short)columnList.indexOf(p8Str) );
                    }

                    //P9STR
                    formula = "((SUM("+getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx+":";
                    cycleTime = cycleTime + cycleTimes[8];
                    fullFilledCycleTime = 0;
                    fullFilled = false;
                    i = 0;
                    while ( !fullFilled && i < 12 )
                    {
                        fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];
                        if( fullFilledCycleTime >= cycleTime )
                        {
                            fullFilled = true;
                        }
                        else
                        {
                            i++;
                        }
                    }

                    if( i >= 12 )
                    {
                    	formula = "";
                    }
                    else if ( fullFilledCycleTime > cycleTime )
                    {
                        formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i - 1] ) )+mergerIdx+") + (("
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx + "/"
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+2 +")*"
                                    + ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))/"
                                    + getAlphaforIdx( columnList.indexOf( ndpwStr ) )+mergerIdx+")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( p1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( p8Str ) )+mergerIdx+")";
                    }
                    else
                    {
                        formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx+"))/"
                                    + getAlphaforIdx( columnList.indexOf( ndpwStr ) )+mergerIdx + ")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( p1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( p8Str ) )+mergerIdx+")";
                        /*}
                        else
                        {
                            formula = "";
                        }*/
                    }
                    
                    if( formula.length() > 1 )
                    {
                        setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                        mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(p9Str), nextRowNumber- 2, (short)columnList.indexOf(p9Str) );
                    }
                    else
                    {
                        setCellValue( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, 0, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
                        mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(p9Str), nextRowNumber- 2, (short)columnList.indexOf(p9Str) );
                    }


                    //P10STR
                    formula = "((SUM("+getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx+":";
                    cycleTime = cycleTime + cycleTimes[9];
                    fullFilledCycleTime = 0;
                    fullFilled = false;
                    i = 0;
                    while ( !fullFilled && i < 12 )
                    {
                        fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];
                        if( fullFilledCycleTime >= cycleTime )
                        {
                            fullFilled = true;
                        }
                        else
                        {
                            i++;
                        }
                    }

                    if( i >= 12 )
                    {
                    	formula = "";
                    }
                    else if ( fullFilledCycleTime > cycleTime )
                    {
                        formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i - 1] ) )+mergerIdx+") + (("
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx + "/"
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+2 +")*"
                                    + ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))/"
                                    + getAlphaforIdx( columnList.indexOf( ndpwStr ) )+mergerIdx+")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( p1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( p9Str ) )+mergerIdx+")";
                    }
                    else
                    {
                        //if ( i < 12 )
                        //{
                            formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx+"))/"
                                    + getAlphaforIdx( columnList.indexOf( ndpwStr ) )+mergerIdx + ")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( p1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( p9Str ) )+mergerIdx+")";
                        /*}
                        else
                        {
                            formula = "";
                        } */
                    }
                    if (formula.length() > 1 )
                    {
                        setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                        mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(p10Str), nextRowNumber- 2, (short)columnList.indexOf(p10Str) );
                    }
                    else
                    {
                        setCellValue( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, 0, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
                        mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(p10Str), nextRowNumber- 2, (short)columnList.indexOf(p10Str) );
                    }

                    mergerIdx = nextRowNumber;
                }
                prevFabPart = waferStartData.getFabPartNumber();
                prevCycleTime = (waferStartData.getFabCycleTime() + waferStartData.getSortCycleTime() + waferStartData.getAssemblyCycleTime() + waferStartData.getTestCycleTime() + waferStartData.getEolCycleTime())/7;
            }
        }
        catch(Exception e)
        {
        	e.printStackTrace();
        }
        return workbook;
    }

    public  Workbook getWorkbookForAssyStartReport (ArrayList<WaferStartData> waferStartDataList, String reportName, String fctframe, String reportType ) throws ScalarException
    {
        Workbook workbook   = null;
        Sheet sheet       = null;
        if ( "xlsx".equalsIgnoreCase(ConfigManager.getXLSWorkBookFormat() ) )
        {
            workbook    = new XSSFWorkbook();
        }
        else
        {
            workbook    = new HSSFWorkbook();
        }
        CreationHelper ch = workbook.getCreationHelper();
        DataFormat df = ch.createDataFormat();

        sheet       = workbook.createSheet( reportName );
        sheet.createFreezePane(0, 4,0,4);
        boolean bufferQtyAdded = false;

        sheet.setSelected( true );
        Font titleFont = workbook.createFont();
        titleFont.setFontHeightInPoints ( ( short ) 8 );
        titleFont.setBoldweight ( Font.BOLDWEIGHT_BOLD );
        titleFont.setFontName( "verdana" );
        titleFont.setColor ( IndexedColors.BLACK.getIndex());

        Font headerFont = workbook.createFont();
        headerFont.setFontHeightInPoints ( ( short ) 8 );
        headerFont.setBoldweight ( Font.BOLDWEIGHT_BOLD );
        headerFont.setFontName( "verdana" );
        headerFont.setColor ( IndexedColors.BLACK.getIndex());

        Font textFont = workbook.createFont();
        textFont.setFontHeightInPoints ( ( short ) 8 );
        textFont.setBoldweight ( Font.BOLDWEIGHT_NORMAL );
        textFont.setFontName( "verdana" );
        textFont.setColor ( IndexedColors.BLACK.getIndex());

        CellStyle titleStyle  = workbook.createCellStyle ( );
        titleStyle.setBorderBottom ( CellStyle.BORDER_THIN );
        titleStyle.setBorderTop ( CellStyle.BORDER_THIN );
        titleStyle.setBorderLeft ( CellStyle.BORDER_THIN );
        titleStyle.setBorderRight ( CellStyle.BORDER_THIN );
        titleStyle.setAlignment ( CellStyle.ALIGN_CENTER );
        titleStyle.setWrapText ( true );
        titleStyle.setFont ( titleFont );

        CellStyle headerStyle  = workbook.createCellStyle ( );
        headerStyle.setBorderBottom ( CellStyle.BORDER_THIN );
        headerStyle.setBorderTop ( CellStyle.BORDER_THIN );
        headerStyle.setBorderLeft ( CellStyle.BORDER_THIN );
        headerStyle.setBorderRight ( CellStyle.BORDER_THIN );
        headerStyle.setAlignment ( CellStyle.ALIGN_CENTER );
        headerStyle.setWrapText ( true );
        headerStyle.setFont ( headerFont );

        CellStyle productValueStyle  = workbook.createCellStyle ( );
        productValueStyle.setBorderBottom ( CellStyle.BORDER_THIN );
        productValueStyle.setBorderTop ( CellStyle.BORDER_THIN );
        productValueStyle.setBorderLeft ( CellStyle.BORDER_THIN );
        productValueStyle.setBorderRight ( CellStyle.BORDER_THIN );
        productValueStyle.setAlignment ( CellStyle.ALIGN_RIGHT );
        productValueStyle.setWrapText ( true );
        productValueStyle.setFont ( textFont );
        productValueStyle.setDataFormat( df.getFormat( "#,##0" ) );

        CellStyle productValueBoldStyle  = workbook.createCellStyle ( );
        productValueBoldStyle.setBorderBottom ( CellStyle.BORDER_THIN );
        productValueBoldStyle.setBorderTop ( CellStyle.BORDER_THIN );
        productValueBoldStyle.setBorderLeft ( CellStyle.BORDER_THIN );
        productValueBoldStyle.setBorderRight ( CellStyle.BORDER_THIN );
        productValueBoldStyle.setAlignment ( CellStyle.ALIGN_RIGHT );
        productValueBoldStyle.setWrapText ( true );
        productValueBoldStyle.setFont ( headerFont );
        productValueBoldStyle.setDataFormat( df.getFormat( "#,##0" ) );

        CellStyle thousandValueStyle  = workbook.createCellStyle ( );
        thousandValueStyle.setBorderBottom ( CellStyle.BORDER_THIN );
        thousandValueStyle.setBorderTop ( CellStyle.BORDER_THIN );
        thousandValueStyle.setBorderLeft ( CellStyle.BORDER_THIN );
        thousandValueStyle.setBorderRight ( CellStyle.BORDER_THIN );
        thousandValueStyle.setAlignment ( CellStyle.ALIGN_RIGHT );
        thousandValueStyle.setWrapText ( true );
        thousandValueStyle.setFont ( textFont );
        thousandValueStyle.setDataFormat( df.getFormat( "# ?/?" ) );

        CellStyle yieldStyle  = workbook.createCellStyle ( );
        yieldStyle.setBorderBottom ( CellStyle.BORDER_THIN );
        yieldStyle.setBorderTop ( CellStyle.BORDER_THIN );
        yieldStyle.setBorderLeft ( CellStyle.BORDER_THIN );
        yieldStyle.setBorderRight ( CellStyle.BORDER_THIN );
        yieldStyle.setAlignment ( CellStyle.ALIGN_RIGHT );
        yieldStyle.setWrapText ( true );
        yieldStyle.setFont ( textFont );
        yieldStyle.setDataFormat( df.getFormat( "0%" ) );

        CellStyle productStyle  = workbook.createCellStyle ( );
        productStyle.setBorderBottom ( CellStyle.BORDER_THIN );
        productStyle.setBorderTop ( CellStyle.BORDER_THIN );
        productStyle.setBorderLeft ( CellStyle.BORDER_THIN );
        productStyle.setBorderRight ( CellStyle.BORDER_THIN );
        productStyle.setAlignment ( CellStyle.ALIGN_LEFT );
        productStyle.setWrapText ( true );
        productStyle.setFont ( textFont );

        CellStyle dateStyle  = workbook.createCellStyle ( );
        dateStyle.setBorderBottom ( CellStyle.BORDER_THIN );
        dateStyle.setBorderTop ( CellStyle.BORDER_THIN );
        dateStyle.setBorderLeft ( CellStyle.BORDER_THIN );
        dateStyle.setBorderRight ( CellStyle.BORDER_THIN );
        dateStyle.setAlignment ( CellStyle.ALIGN_RIGHT );
        dateStyle.setWrapText ( true );
        dateStyle.setFont ( textFont );
        dateStyle.setDataFormat( df.getFormat( "m/d/yy" ) );

        //SETTING HEADINGS
        final String fabPartStr = "Wafer Part";
        final String fgPartStr = "FG Part";
        final String assemblyPartStr = "Assembly Part";
        final String chipSetStr = "Chip Set";
        /*final String productLineStr = "Product Line";
        final String chipFamilyStr = "Chip Family";
        final String process = "Process";
        final String waferCost = "Wafer Cost";*/
        final String currentQtrFct = DataDumpReportsDAO.getQuarterString(0)+" Fct";
        final String nextQtrFct = DataDumpReportsDAO.getQuarterString(1)+" Fct";
        final String nextNextQtrFct = DataDumpReportsDAO.getQuarterString(2)+" Fct";
        final String nextNextNextQtrFct = DataDumpReportsDAO.getQuarterString(3)+" Fct";
        final String currentQtrShipments = DataDumpReportsDAO.getQuarterString(0)+" Shipment";
        final String currentQtrBacklog = DataDumpReportsDAO.getQuarterString(0)+" Backlog";
        final String bufferQtyStr = "Buffer Qty";
        final String diePerPackageQtyStr = "Dies Per Package";
        final String fabYieldStr = "Fab Std Yield";
        final String sortYieldStr = "Sort Std Yield";
        final String assemblyYieldStr = "Assembly Std Yield";
        final String ftYieldStr = "FT Yield";
        final String totalYieldStr = "Total Yield";
        final String gdwStr	= "GDW";
        final String ndpwStr = "NDPW";
        final String waitingForWSStr = "Waiting For W/S (Wfr)";
        final String fabStr = "Fab(Wfr)";
        final String wsStr = "Wafer Store(Wfr)";
        final String sortStr = "Sort(Wfr)";
        final String dieBankStr = "Die Bank";
        final String backEndDieStr = "Total Front End Die";
        final String assemblyStr = "Assembly";
        final String assemlbyReleaseStr = "Assembly Release";
        final String preTestStr = "Pre Test";
        final String finalTestStr =  "Final Test";
        final String eolStr = "EOL";
        final String fgStr = "Finished Goods";
        final String totDieAvailableStr = "Total Back End Die";
        final String fabCycleTime = "Fab Cycle Time";
        final String sortCycleTime = "Sort Cycle Time";
        final String assemblyCycleTime = "Assembly Cycle Time";
        final String testCycleTime = "Test Cycle Time";
        final String eolCycleTime = "EOL Cycle Time";
        final String totalCycleTime = "Cycle Time";

        Calendar cal = Calendar.getInstance();
        int year = cal.get( Calendar.YEAR );
        int qtrNo = DateUtil.getQuarterOfMonth(cal.get(Calendar.MONTH)+1);;

        int qtrStartMth = DateUtil.getStartMonthOfQtr( qtrNo );
        
        int[] cycleTimes = new int[12];
        String[] monthArray = new String[12];

        cal.clear();
        cal.set( year, qtrStartMth-1, 1 ); //setting to current qtr start month
        final String m1Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase();
        final String b1Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+" ";
        final String w1Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"  ";
        final String bklg1 = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+ "_Backlog";

        cal.add( Calendar.MONTH, 1 );
        final String m2Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase();
        final String b2Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+" ";
        final String w2Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"  ";
        final String bklg2 = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+ "_Backlog";

        cal.add( Calendar.MONTH, 1 );
        final String m3Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase();
        final String b3Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+" ";
        final String w3Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"  ";
        final String bklg3 = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+ "_Backlog";
        cal.add( Calendar.MONTH, 1 );
        final String m4Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase();
        final String b4Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+" ";
        final String w4Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"  ";
        final String bklg4 = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+ "_Backlog";
        cal.add( Calendar.MONTH, 1 );
        final String m5Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase();
        final String b5Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+" ";
        final String w5Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"  ";
        final String bklg5 = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+ "_Backlog";
        cal.add( Calendar.MONTH, 1 );
        final String m6Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase();
        final String b6Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+" ";
        final String w6Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"  ";
        final String bklg6 = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+ "_Backlog";
        cal.add( Calendar.MONTH, 1 );
        final String m7Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase();
        final String b7Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+" ";
        final String w7Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"  ";
        final String bklg7 = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+ "_Backlog";
        cal.add( Calendar.MONTH, 1 );
        final String m8Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase();
        final String b8Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+" ";
        final String w8Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"  ";
        final String bklg8 = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+ "_Backlog";
        cal.add( Calendar.MONTH, 1 );
        final String m9Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase();
        final String b9Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+" ";
        final String w9Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"  ";
        final String bklg9 = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+ "_Backlog";
        cal.add( Calendar.MONTH, 1 );
        final String m10Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase();
        final String b10Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+" ";
        final String w10Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"  ";
        final String bklg10 = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+ "_Backlog";
        cal.add( Calendar.MONTH, 1 );
        final String m11Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase();
        final String b11Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+" ";
        final String w11Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"  ";
        final String bklg11 = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+ "_Backlog";
        cal.add( Calendar.MONTH, 1 );
        final String m12Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase();
        final String b12Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+" ";
        final String w12Str = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+"  ";
        final String bklg12 = DateUtil.formatDate( cal.getTime(), "MMM_yy" ).toUpperCase()+ "_Backlog";
        
        cal.clear();
        cal.set( year, qtrStartMth-1, 1 );
        Period period = CalendarDAO.getQuarterByCompanyCalender( new Date() );
        cal.setTime( StringUtils.format( period.getStartDate() ) );

        String workWeek = CalendarDAO.getCompanyClaendarWorkWeek( null, StringUtils.formatDateToString( cal.getTime() ) );
        try
        {
        	Integer.parseInt( workWeek );
        }
        catch (Exception e)
        {
        	//In case of parsing exception, make the work week as 1.
        	e.printStackTrace();
        	workWeek = "01";
        }
        
        final String ww1Str = "WW_"+ workWeek;
        final String ww2Str = "WW_"+ (Integer.parseInt( workWeek ) + 1 );
        final String ww3Str = "WW_"+ (Integer.parseInt( workWeek ) + 2 );
		final String ww4Str = "WW_"+ (Integer.parseInt( workWeek ) + 3 );
		final String ww5Str = "WW_"+ (Integer.parseInt( workWeek ) + 4 );
		final String ww6Str = "WW_"+ (Integer.parseInt( workWeek ) + 5 );
		final String ww7Str = "WW_"+ (Integer.parseInt( workWeek ) + 6 );
		final String ww8Str = "WW_"+ (Integer.parseInt( workWeek ) + 7 );
		final String ww9Str = "WW_"+ (Integer.parseInt( workWeek ) + 8 );
		final String ww10Str = "WW_"+ (Integer.parseInt( workWeek ) + 9 );
		final String ww11Str = "WW_"+ (Integer.parseInt( workWeek ) + 10 );
		final String ww12Str = "WW_"+ (Integer.parseInt( workWeek ) + 11 );
		final String ww13Str = "WW_"+ (Integer.parseInt( workWeek ) + 12 );
		final String ww14Str = "WW_"+ (Integer.parseInt( workWeek ) + 13 );
		final String ww15Str = "WW_"+ (Integer.parseInt( workWeek ) + 14 );
		final String ww16Str = "WW_"+ (Integer.parseInt( workWeek ) + 15 );
		final String ww17Str = "WW_"+ (Integer.parseInt( workWeek ) + 16 );

        String headers[] = { fabPartStr, assemblyPartStr, fgPartStr, currentQtrFct, currentQtrShipments,
        		currentQtrBacklog, nextQtrFct, nextNextQtrFct, nextNextNextQtrFct,
        		bklg1, bklg2, bklg3, bklg4, bklg5, bklg6, bklg7, bklg8, bklg9, bklg10, bklg11, bklg12,
        		bufferQtyStr,diePerPackageQtyStr,
        		fabYieldStr, sortYieldStr, assemblyYieldStr, ftYieldStr, totalYieldStr, gdwStr, ndpwStr,
                waitingForWSStr,
                fabStr, wsStr, sortStr, dieBankStr, backEndDieStr, assemblyStr, assemlbyReleaseStr, preTestStr, finalTestStr, eolStr, fgStr,
                totDieAvailableStr, m1Str, m2Str, m3Str, m4Str, m5Str, m6Str, m7Str, m8Str, m9Str, m10Str, m11Str, m12Str
                ,b1Str, b2Str, b3Str, b4Str, b5Str, b6Str, b7Str, b8Str, b9Str, b10Str, b11Str, b12Str
                , fabCycleTime, sortCycleTime, assemblyCycleTime, testCycleTime,eolCycleTime,totalCycleTime,
                w1Str, w2Str, w3Str, w4Str, w5Str, w6Str, w7Str, w8Str, w9Str, w10Str, w11Str, w12Str, ww1Str, ww2Str, ww3Str, ww4Str, ww5Str, ww6Str, ww7Str, ww8Str, ww9Str, ww10Str, ww11Str, ww12Str, ww13Str, ww14Str, ww15Str, ww16Str, ww17Str };

        List<String> columnList = Arrays.asList( headers );
        try
        {
	        Row row = sheet.createRow( 0 );
	        Cell cell = mergeCells( sheet, 0, (short)0, 0, (short)(headers.length-1), titleStyle );
	        setCellValue( cell, ch.createRichTextString("Assembly Build Plan"), titleStyle );

	        row = sheet.createRow( 1 );
	        setCellValue( row, (short)columnList.indexOf(m1Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(m2Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(m3Str), 5, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(m4Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(m5Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(m6Str), 5, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(m7Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(m8Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(m9Str), 5, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(m10Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(m11Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(m12Str), 5, productValueStyle, Cell.CELL_TYPE_NUMERIC  );

	        
	        cal.clear();
	        cal.set( year, qtrStartMth-1, 1 );
	        period = CalendarDAO.getQuarterByCompanyCalender( new Date() );
	        cal.setTime( StringUtils.format( period.getStartDate() ) );
	        if( cal.getTime().before( new Date() ) )
	        {
	        	if( DateUtil.getElapsedDays( cal.getTime(), new Date() ) >= 28 )
	        	{
		        	setCellValue( row, (short)columnList.indexOf(b1Str), 0, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
		        	cycleTimes[0] = 0;
	        	}
	        	else
	        	{
		        	setCellValue( row, (short)columnList.indexOf(b1Str), ( ( 28 - DateUtil.getElapsedDays( cal.getTime(), new Date() ))/7), productValueStyle, Cell.CELL_TYPE_NUMERIC  );
		        	cycleTimes[0] = ( 28 - DateUtil.getElapsedDays( cal.getTime(), new Date() ) )/7;
	        	}	        	
	        }
	        else
	        {
	        	setCellValue( row, (short)columnList.indexOf(b1Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        	cycleTimes[0] = 4;
	        }
	        cal.add( Calendar.DATE, 28 );
	        
	        if( cal.getTime().before( new Date() ) )
	        {
	        	if( DateUtil.getElapsedDays( cal.getTime(), new Date() ) >= 28 )
	        	{
		        	setCellValue( row, (short)columnList.indexOf(b2Str), 0, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
		        	cycleTimes[1] = 0;
	        	}
	        	else
	        	{
		        	setCellValue( row, (short)columnList.indexOf(b2Str), ( (28 - DateUtil.getElapsedDays( cal.getTime(), new Date() ) )/7), productValueStyle, Cell.CELL_TYPE_NUMERIC  );
		        	cycleTimes[1] = ( 28 - DateUtil.getElapsedDays( cal.getTime(), new Date() ))/7;
	        	}	
	        }
	        else
	        {
	        	setCellValue( row, (short)columnList.indexOf(b2Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        	cycleTimes[1] = 4;
	        }
	        
	        //cal.add( Calendar.MONTH, 1 );
	        cal.add( Calendar.DATE, 28 );
	        if( cal.getTime().before( new Date() ) )
	        {
	        	//setCellValue( row, (short)columnList.indexOf(b3Str), 0, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        	//cycleTimes[2] = 0;
	        	if( DateUtil.getElapsedDays( cal.getTime(), new Date() ) >= 35 )
	        	{
		        	setCellValue( row, (short)columnList.indexOf(b3Str), 0, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
		        	cycleTimes[2] = 0;
	        	}
	        	else
	        	{
		        	setCellValue( row, (short)columnList.indexOf(b3Str), ( ( 35 - DateUtil.getElapsedDays( cal.getTime(), new Date() ) )/7), productValueStyle, Cell.CELL_TYPE_NUMERIC  );
		        	cycleTimes[2] = ( 35 - DateUtil.getElapsedDays( cal.getTime(), new Date() ) )/7;
	        	}	
	        }
	        else
	        {
	        	setCellValue( row, (short)columnList.indexOf(b3Str), 5, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        	cycleTimes[2] = 5;
	        }

	        setCellValue( row, (short)columnList.indexOf(b4Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(b5Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(b6Str), 5, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(b7Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(b8Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(b9Str), 5, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(b10Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(b11Str), 4, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(b12Str), 5, productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        cycleTimes[3] = 4;
	        cycleTimes[4] = 4;
	        cycleTimes[5] = 5;
	        cycleTimes[6] = 4;
	        cycleTimes[7] = 4;
	        cycleTimes[8] = 5;
	        cycleTimes[9] = 4;
	        cycleTimes[10] = 4;
	        cycleTimes[11] = 5;

            monthArray[0] = b1Str;
	        monthArray[1] = b2Str;
	        monthArray[2] = b3Str;
	        monthArray[3] = b4Str;
	        monthArray[4] = b5Str;
	        monthArray[5] = b6Str;
	        monthArray[6] = b7Str;
	        monthArray[7] = b8Str;
	        monthArray[8] = b9Str;
	        monthArray[9] = b10Str;
	        monthArray[10] = b11Str;
	        monthArray[11] = b12Str;

	        /*monthArray[0] = w1Str;
	        monthArray[1] = w2Str;
	        monthArray[2] = w3Str;
	        monthArray[3] = w4Str;
	        monthArray[4] = w5Str;
	        monthArray[5] = w6Str;
	        monthArray[6] = w7Str;
	        monthArray[7] = w8Str;
	        monthArray[8] = w9Str;
	        monthArray[9] = w10Str;
	        monthArray[10] = w11Str;
	        monthArray[11] = w12Str;

	        setCellValue( row, (short)columnList.indexOf(w1Str), cycleTimes[0], productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(w2Str), cycleTimes[1], productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(w3Str), cycleTimes[2], productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(w4Str), cycleTimes[3], productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(w5Str), cycleTimes[4], productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(w6Str), cycleTimes[5], productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(w7Str), cycleTimes[6], productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(w8Str), cycleTimes[7], productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(w9Str), cycleTimes[8], productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(w10Str), cycleTimes[9], productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(w11Str), cycleTimes[10], productValueStyle, Cell.CELL_TYPE_NUMERIC  );
	        setCellValue( row, (short)columnList.indexOf(w12Str), cycleTimes[11], productValueStyle, Cell.CELL_TYPE_NUMERIC  );*/

	        row = sheet.createRow( 2 );


	        cell = mergeCells( sheet, 2, (short)columnList.indexOf( fabYieldStr ), 2, (short)columnList.indexOf( ftYieldStr ), titleStyle );
	        setCellValue( cell, ch.createRichTextString("Standard Yields"), titleStyle );

	        cell = mergeCells( sheet, 2, (short)columnList.indexOf(waitingForWSStr), 2, (short)columnList.indexOf(fgStr), titleStyle );
	        setCellValue( cell, ch.createRichTextString("WIP/Inventory"), titleStyle );

	        cell = mergeCells( sheet, 2, (short)columnList.indexOf(m1Str), 2, (short)columnList.indexOf(m12Str), titleStyle );
	        setCellValue( cell, ch.createRichTextString("Unit Demand"), titleStyle );

	        cell = mergeCells( sheet, 2, (short)columnList.indexOf(b1Str), 2, (short)columnList.indexOf(b12Str), titleStyle );
	        setCellValue( cell, ch.createRichTextString("Unsupplied Forecast"), titleStyle );

	        cell = mergeCells( sheet, 2, (short)columnList.indexOf(w1Str), 2, (short)columnList.indexOf(w12Str), titleStyle );
	        setCellValue( cell, ch.createRichTextString("Assy Start Period -Die"), titleStyle );

	        cell = mergeCells( sheet, 2, (short)columnList.indexOf(fabCycleTime), 2, (short)columnList.indexOf(eolCycleTime), titleStyle );
	        setCellValue( cell, ch.createRichTextString("Standard Cycle Times"), titleStyle );

	        row = sheet.createRow ( 3 );

	        for ( int i = 0; i < headers.length; i++ )
	        {
	            cell    = row.createCell( i );
	            setCellValue( cell, ch.createRichTextString(headers[i]), headerStyle );

	            if ( headers[i].equalsIgnoreCase( fabYieldStr ) || headers[i].equalsIgnoreCase( sortYieldStr ) ||
	            		headers[i].equalsIgnoreCase( assemblyYieldStr) || headers[i].equalsIgnoreCase( ftYieldStr ) ||
						headers[i].equalsIgnoreCase( waitingForWSStr ) || headers[i].equalsIgnoreCase( fabStr ) ||
						headers[i].equalsIgnoreCase( wsStr ) || headers[i].equalsIgnoreCase( sortStr ) || headers[i].equalsIgnoreCase( dieBankStr ) ||
						headers[i].equalsIgnoreCase( backEndDieStr ) || headers[i].equalsIgnoreCase( assemblyStr ) || headers[i].equalsIgnoreCase( assemlbyReleaseStr ) || headers[i].equalsIgnoreCase( preTestStr ) ||
						headers[i].equalsIgnoreCase( finalTestStr ) || headers[i].equalsIgnoreCase( eolStr ) || headers[i].equalsIgnoreCase( fgStr ) ||
						headers[i].equalsIgnoreCase( fabCycleTime ) || headers[i].equalsIgnoreCase( sortCycleTime ) || headers[i].equalsIgnoreCase( assemblyCycleTime ) ||
						headers[i].equalsIgnoreCase( testCycleTime ) || headers[i].equalsIgnoreCase( eolCycleTime ) || headers[i].equalsIgnoreCase( gdwStr ) ||
						headers[i].equalsIgnoreCase( m1Str ) || headers[i].equalsIgnoreCase( m2Str ) || headers[i].equalsIgnoreCase( m3Str ) || headers[i].equalsIgnoreCase( m4Str ) ||
						headers[i].equalsIgnoreCase( m5Str ) || headers[i].equalsIgnoreCase( m6Str ) || headers[i].equalsIgnoreCase( m7Str ) || headers[i].equalsIgnoreCase( m8Str ) ||
						headers[i].equalsIgnoreCase( m9Str ) || headers[i].equalsIgnoreCase( m10Str ) || headers[i].equalsIgnoreCase( m11Str ) || headers[i].equalsIgnoreCase( m12Str ) ||
						headers[i].equalsIgnoreCase( b1Str ) || headers[i].equalsIgnoreCase( b2Str ) || headers[i].equalsIgnoreCase( b3Str ) || headers[i].equalsIgnoreCase( b4Str ) ||
						headers[i].equalsIgnoreCase( b5Str ) || headers[i].equalsIgnoreCase( b6Str ) || headers[i].equalsIgnoreCase( b7Str ) || headers[i].equalsIgnoreCase( b8Str ) ||
						headers[i].equalsIgnoreCase( b9Str ) || headers[i].equalsIgnoreCase( b10Str ) || headers[i].equalsIgnoreCase( b11Str ) || headers[i].equalsIgnoreCase( b12Str )||
						headers[i].equalsIgnoreCase( bklg1 ) || headers[i].equalsIgnoreCase( bklg2 ) || headers[i].equalsIgnoreCase(  bklg3 ) || headers[i].equalsIgnoreCase( bklg4 ) || 
						headers[i].equalsIgnoreCase(  bklg5 ) || headers[i].equalsIgnoreCase(  bklg6 ) || headers[i].equalsIgnoreCase(  bklg7 ) || headers[i].equalsIgnoreCase(  bklg8 ) || 
						headers[i].equalsIgnoreCase(  bklg9 ) || headers[i].equalsIgnoreCase(  bklg10 ) || headers[i].equalsIgnoreCase(  bklg11 ) || headers[i].equalsIgnoreCase(  bklg12 )
						/*||						
						headers[i].equalsIgnoreCase( w1Str ) || headers[i].equalsIgnoreCase( w2Str ) || headers[i].equalsIgnoreCase( w3Str ) */ 
					)
	            {
	                sheet.setColumnWidth( i, 0 );// Change this to sheet.setColumnWidth( i, 0  ) to hide columns
	            }
	            else if(  headers[i].equalsIgnoreCase( fgPartStr ) )
	            {
	            	sheet.setColumnWidth( i, ( ( ( 30 ) * 256 ) ) );
	            }
	            else if(  headers[i].equalsIgnoreCase( chipSetStr ) )
	            {
	            	sheet.setColumnWidth( i, ( ( ( 18 ) * 256 ) ) );
	            }
	            else
	            {
	                sheet.setColumnWidth( i, ( ( ( 12 ) * 256 ) ) );
	            }
	        }
	        
	        if( cycleTimes[0] == 0 )// Hiding the columns when the month is past
	        {
	        	sheet.setColumnWidth( columnList.indexOf(ww1Str) , 0 );
	        	sheet.setColumnWidth( columnList.indexOf(ww2Str) , 0 );
	        	sheet.setColumnWidth( columnList.indexOf(ww3Str) , 0 );
	        	sheet.setColumnWidth( columnList.indexOf(ww4Str) , 0 );
	        }

	        if( cycleTimes[1] == 0 )// Hiding the columns when the month is past
	        {
	        	sheet.setColumnWidth( columnList.indexOf(ww5Str) , 0 );
	        	sheet.setColumnWidth( columnList.indexOf(ww6Str) , 0 );
	        	sheet.setColumnWidth( columnList.indexOf(ww7Str) , 0 );
	        	sheet.setColumnWidth( columnList.indexOf(ww8Str) , 0 );
	        }

	        if( cycleTimes[3] == 0 )// Hiding the columns when the month is past
	        {
	        	sheet.setColumnWidth( columnList.indexOf(ww9Str) , 0 );
	        	sheet.setColumnWidth( columnList.indexOf(ww10Str) , 0 );
	        	sheet.setColumnWidth( columnList.indexOf(ww11Str) , 0 );
	        	sheet.setColumnWidth( columnList.indexOf(ww12Str) , 0 );
	        	sheet.setColumnWidth( columnList.indexOf(ww13Str) , 0 );
	        }
	        
	        if( cycleTimes[0] > 0 || cycleTimes[1] > 0 )
	        {
	        	sheet.setColumnWidth( columnList.indexOf(ww14Str) , 0 );
	        	sheet.setColumnWidth( columnList.indexOf(ww15Str) , 0 );
	        	sheet.setColumnWidth( columnList.indexOf(ww16Str) , 0 );
	        	sheet.setColumnWidth( columnList.indexOf(ww17Str) , 0 );
	        }

	        int nextRowNumber   = 4;
	        int nextColumnIdx = 0;
	        String formula = "";
            String prevAssmPart = "";
            int prevCycleTime = 0;
	        int mergerIdx = nextRowNumber + 1;
	        for ( WaferStartData waferStartData: waferStartDataList )
	        {
	        	bufferQtyAdded = false;
	        	nextColumnIdx = 0;
	        	row = sheet.createRow( nextRowNumber );
	        	nextRowNumber++;

	        	setCellValue( row, (short)nextColumnIdx++, ch.createRichTextString(waferStartData.getFabPartNumber()), productStyle  );
	        	setCellValue( row, (short)nextColumnIdx++, ch.createRichTextString(waferStartData.getAssemblyPartNumber()), productStyle  );
	        	setCellValue( row, (short)nextColumnIdx++, ch.createRichTextString(waferStartData.getFgPartNumber()), productStyle  );
	        	/*setCellValue( row, (short)nextColumnIdx++, ch.createRichTextString(waferStartData.getChipSet()), productStyle  );
	        	setCellValue( row, (short)nextColumnIdx++, ch.createRichTextString(waferStartData.getProductLine()), productStyle  );
	        	setCellValue( row, (short)nextColumnIdx++, ch.createRichTextString(waferStartData.getChipFamily()), productStyle  );
	            setCellValue( row, (short)nextColumnIdx++, ch.createRichTextString(waferStartData.getProcess()), productStyle  );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getWaferCost(), productStyle, Cell.CELL_TYPE_NUMERIC   );*/

                if("month".equalsIgnoreCase(fctframe)) {
                    String qtrformula = getCellReference(columnList.indexOf(m1Str), nextRowNumber)+
                                    "+"+getCellReference(columnList.indexOf(m2Str), nextRowNumber)+
                                    "+"+getCellReference(columnList.indexOf(m3Str), nextRowNumber);
                    setCellFormula( row, (short)nextColumnIdx++, qtrformula, productValueStyle );
                } else {
                    setCellValue( row, (short)nextColumnIdx++, waferStartData.getCurrent_Qtr_Forecast(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
                }

	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getCurrent_Qtr_Shipped_Qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getCurrent_Qtr_Backlog(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
                if("month".equalsIgnoreCase(fctframe)) {
                    String qtrformula = getCellReference(columnList.indexOf(m4Str), nextRowNumber)+
                                    "+"+getCellReference(columnList.indexOf(m5Str), nextRowNumber)+
                                    "+"+getCellReference(columnList.indexOf(m6Str), nextRowNumber);
                    setCellFormula( row, (short)nextColumnIdx++, qtrformula, productValueStyle );

                    qtrformula = getCellReference(columnList.indexOf(m7Str), nextRowNumber)+
                                    "+"+getCellReference(columnList.indexOf(m8Str), nextRowNumber)+
                                    "+"+getCellReference(columnList.indexOf(m9Str), nextRowNumber);
                    setCellFormula( row, (short)nextColumnIdx++, qtrformula, productValueStyle );

                    qtrformula = getCellReference(columnList.indexOf(m10Str), nextRowNumber)+
                                    "+"+getCellReference(columnList.indexOf(m11Str), nextRowNumber)+
                                    "+"+getCellReference(columnList.indexOf(m12Str), nextRowNumber);
                    setCellFormula( row, (short)nextColumnIdx++, qtrformula, productValueStyle );
                } else {
                    setCellValue( row, (short)nextColumnIdx++, waferStartData.getQ1_Forecast(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
                    setCellValue( row, (short)nextColumnIdx++, waferStartData.getQ2_Forecast(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	                setCellValue( row, (short)nextColumnIdx++, waferStartData.getQ3_Forecast(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
                }
                setCellValue( row, (short)nextColumnIdx++, waferStartData.getM1_bklg_qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
                setCellValue( row, (short)nextColumnIdx++, waferStartData.getM2_bklg_qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
                setCellValue( row, (short)nextColumnIdx++, waferStartData.getM3_bklg_qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
                setCellValue( row, (short)nextColumnIdx++, waferStartData.getM4_bklg_qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
                setCellValue( row, (short)nextColumnIdx++, waferStartData.getM5_bklg_qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
                setCellValue( row, (short)nextColumnIdx++, waferStartData.getM6_bklg_qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
                setCellValue( row, (short)nextColumnIdx++, waferStartData.getM7_bklg_qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
                setCellValue( row, (short)nextColumnIdx++, waferStartData.getM8_bklg_qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
                setCellValue( row, (short)nextColumnIdx++, waferStartData.getM9_bklg_qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
                setCellValue( row, (short)nextColumnIdx++, waferStartData.getM10_bklg_qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
                setCellValue( row, (short)nextColumnIdx++, waferStartData.getM11_bklg_qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
                setCellValue( row, (short)nextColumnIdx++, waferStartData.getM12_bklg_qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
                

	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getFg_min_level_Qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getDiePerPackage(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getFab_Yield(), yieldStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getSort_Yield(), yieldStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getAssembly_Yield(), yieldStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getTest_Yield(), yieldStyle, Cell.CELL_TYPE_NUMERIC   );

	            String totalYieldFormula = getCellReference(columnList.indexOf(assemblyYieldStr),nextRowNumber)+
	                            "*"+getCellReference(columnList.indexOf(ftYieldStr),nextRowNumber);
	            setCellFormula( row, (short)nextColumnIdx++, totalYieldFormula, yieldStyle );

	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getGdw()<1?1:waferStartData.getGdw(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            String netDieFormula = getAlphaforIdx(columnList.indexOf(gdwStr))+nextRowNumber+
	            "*"+getAlphaforIdx(columnList.indexOf(totalYieldStr))+nextRowNumber;
	            setCellFormula( row, (short)nextColumnIdx++, netDieFormula, productValueStyle );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getOpen_PO_Qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getFab_Qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getWafer_Store_Qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getSort_Qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getDb_Qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );

                formula = "("+getAlphaforIdx(columnList.indexOf(waitingForWSStr))+nextRowNumber+
                "+"+getAlphaforIdx(columnList.indexOf(fabStr))+nextRowNumber+")"+
                "*"+getAlphaforIdx(columnList.indexOf(fabYieldStr))+nextRowNumber+
                "*"+getAlphaforIdx(columnList.indexOf(sortYieldStr))+nextRowNumber+
                "*"+getAlphaforIdx(columnList.indexOf(assemblyYieldStr))+nextRowNumber+
                "*"+getAlphaforIdx(columnList.indexOf(ftYieldStr))+nextRowNumber+
                "*"+getAlphaforIdx(columnList.indexOf(gdwStr))+nextRowNumber+
                "+("+getAlphaforIdx(columnList.indexOf( wsStr ))+nextRowNumber+
                "+"+getAlphaforIdx(columnList.indexOf( sortStr ))+nextRowNumber+")"+
                "*"+getAlphaforIdx(columnList.indexOf(sortYieldStr))+nextRowNumber+
                "*"+getAlphaforIdx(columnList.indexOf(assemblyYieldStr))+nextRowNumber+
                "*"+getAlphaforIdx(columnList.indexOf(ftYieldStr))+nextRowNumber+
                "*"+getAlphaforIdx(columnList.indexOf(gdwStr))+nextRowNumber+
                "+("+getAlphaforIdx(columnList.indexOf( dieBankStr ))+nextRowNumber+")"+
                "*"+getAlphaforIdx(columnList.indexOf(assemblyYieldStr))+nextRowNumber+
                "*"+getAlphaforIdx(columnList.indexOf(ftYieldStr))+nextRowNumber;

	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getAssembly_Qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getAssemblyReleaseQty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getPreTest_Qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getTest_Qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getEol_Qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getFg_Qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );

	            String totalDieAvailableFormula = "("+getAlphaforIdx(columnList.indexOf( assemblyStr ))+nextRowNumber+"+"+ getCellReference(columnList.indexOf( assemlbyReleaseStr ), nextRowNumber) + ")"+
            	"*"+getAlphaforIdx(columnList.indexOf(assemblyYieldStr))+nextRowNumber+
            	"*"+getAlphaforIdx(columnList.indexOf(ftYieldStr))+nextRowNumber+
            	"+("+getAlphaforIdx(columnList.indexOf( preTestStr ))+nextRowNumber+")"+
            	"*"+getAlphaforIdx(columnList.indexOf(ftYieldStr))+nextRowNumber+
            	"+("+getAlphaforIdx(columnList.indexOf( finalTestStr ))+nextRowNumber+")"+
            	"*"+getAlphaforIdx(columnList.indexOf(ftYieldStr))+nextRowNumber+
            	"+"+getAlphaforIdx(columnList.indexOf( eolStr ))+nextRowNumber+
            	"+"+getAlphaforIdx(columnList.indexOf( fgStr ))+nextRowNumber	;
	            setCellFormula( row, (short)nextColumnIdx++, totalDieAvailableFormula, productValueStyle );

	            /*String currentQtrQty = "";
                if ((waferStartData.getCurrent_Qtr_Backlog() + waferStartData.getCurrent_Qtr_Shipped_Qty()) > waferStartData.getCurrent_Qtr_Forecast()) {
                    currentQtrQty = currentQtrBacklog;
                } else {
                    currentQtrQty = currentQtrFct;
                }*/
	            if( "Backlog".equalsIgnoreCase( reportType ) )
	            {
	            	setCellValue( row, (short)nextColumnIdx++, waferStartData.getM1_bklg_qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            	setCellValue( row, (short)nextColumnIdx++, waferStartData.getM2_bklg_qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            	setCellValue( row, (short)nextColumnIdx++, waferStartData.getM3_bklg_qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            	setCellValue( row, (short)nextColumnIdx++, waferStartData.getM4_bklg_qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            	setCellValue( row, (short)nextColumnIdx++, waferStartData.getM5_bklg_qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            	setCellValue( row, (short)nextColumnIdx++, waferStartData.getM6_bklg_qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            	setCellValue( row, (short)nextColumnIdx++, waferStartData.getM7_bklg_qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            	setCellValue( row, (short)nextColumnIdx++, waferStartData.getM8_bklg_qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            	setCellValue( row, (short)nextColumnIdx++, waferStartData.getM9_bklg_qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            	setCellValue( row, (short)nextColumnIdx++, waferStartData.getM10_bklg_qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            	setCellValue( row, (short)nextColumnIdx++, waferStartData.getM11_bklg_qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            	setCellValue( row, (short)nextColumnIdx++, waferStartData.getM12_bklg_qty(), productValueStyle, Cell.CELL_TYPE_NUMERIC   );
	            }
	            else
	            {
	                //formula = "month".equalsIgnoreCase(fctframe)? waferStartData.getM1_fc_qty()+"" : "((" + getAlphaforIdx(columnList.indexOf(currentQtrQty)) + nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m1Str))+ 2 )+")";
	                if ((waferStartData.getCurrent_Qtr_Backlog() + waferStartData.getCurrent_Qtr_Shipped_Qty()) > waferStartData.getCurrent_Qtr_Forecast()) 
	                {
	                	formula = "month".equalsIgnoreCase(fctframe)? ( waferStartData.getM1_fc_qty() > waferStartData.getCurrent_Qtr_Shipped_Qty()? waferStartData.getM1_fc_qty()- waferStartData.getCurrent_Qtr_Shipped_Qty():0 )+"" : "(((" + getAlphaforIdx(columnList.indexOf(currentQtrBacklog)) + nextRowNumber + ")/13)*"+ (getAlphaforIdx(columnList.indexOf(m1Str))+ 2 )+")";
	                }
	                else
	                {
	                	formula = "month".equalsIgnoreCase(fctframe)? ( waferStartData.getM1_fc_qty() > waferStartData.getCurrent_Qtr_Shipped_Qty()? waferStartData.getM1_fc_qty()- waferStartData.getCurrent_Qtr_Shipped_Qty():0 )+"" : "(((" + getAlphaforIdx(columnList.indexOf(currentQtrFct)) + nextRowNumber +"-" + getAlphaforIdx( columnList.indexOf( currentQtrShipments ) )+ nextRowNumber + ")/13)*"+ (getAlphaforIdx(columnList.indexOf(m1Str))+ 2 )+")";
	                }
	                setCellFormula(row, (short) nextColumnIdx++, formula, productValueStyle);
	
	                //add the buffer quantity to this months forecast if this is not the current month
	                if ((waferStartData.getCurrent_Qtr_Backlog() + waferStartData.getCurrent_Qtr_Shipped_Qty()) > waferStartData.getCurrent_Qtr_Forecast()) 
	                {
	                	formula = "month".equalsIgnoreCase(fctframe)? ( ( waferStartData.getM2_fc_qty()+ waferStartData.getM1_fc_qty() ) > waferStartData.getCurrent_Qtr_Shipped_Qty()? ( waferStartData.getM1_fc_qty() > waferStartData.getCurrent_Qtr_Shipped_Qty()? waferStartData.getM2_fc_qty(): ( waferStartData.getM1_fc_qty() + waferStartData.getM2_fc_qty() ) - waferStartData.getCurrent_Qtr_Shipped_Qty() ) :0 ) +"" :"(((" + getAlphaforIdx(columnList.indexOf(currentQtrBacklog)) + nextRowNumber + ")/13)*"+ (getAlphaforIdx(columnList.indexOf(m2Str))+ 2 )+")";
	                }
	                else
	                {
	                	formula = "month".equalsIgnoreCase(fctframe)? ( ( waferStartData.getM2_fc_qty()+ waferStartData.getM1_fc_qty() ) > waferStartData.getCurrent_Qtr_Shipped_Qty()? ( waferStartData.getM1_fc_qty() > waferStartData.getCurrent_Qtr_Shipped_Qty()? waferStartData.getM2_fc_qty(): ( waferStartData.getM1_fc_qty() + waferStartData.getM2_fc_qty() ) - waferStartData.getCurrent_Qtr_Shipped_Qty() ) :0 ) +"" :"(((" + getAlphaforIdx(columnList.indexOf(currentQtrFct)) + nextRowNumber  +"-" + getAlphaforIdx( columnList.indexOf( currentQtrShipments ) )+ nextRowNumber + ")/13)*"+ (getAlphaforIdx(columnList.indexOf(m2Str))+ 2 )+")";
	                }
	                
	                if (cycleTimes[1] != 0 && bufferQtyAdded == false) {
	                    //formula = "month".equalsIgnoreCase(fctframe)? waferStartData.getM2_fc_qty()+"" : "((" + getAlphaforIdx(columnList.indexOf(currentQtrQty)) + nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m2Str))+ 2 )+")";
	                    formula += "+" + getAlphaforIdx(columnList.indexOf(bufferQtyStr)) + nextRowNumber;
	                    bufferQtyAdded = true;
	                } /*else {
	                    //formula = "month".equalsIgnoreCase(fctframe)? waferStartData.getM2_fc_qty()+"" : "((" + getAlphaforIdx(columnList.indexOf(currentQtrQty)) + nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m2Str))+ 2 )+")";
	                	//formula = "month".equalsIgnoreCase(fctframe)? ( ( waferStartData.getM2_fc_qty()+ waferStartData.getM1_fc_qty() ) > waferStartData.getCurrent_Qtr_Shipped_Qty()? ( waferStartData.getM1_fc_qty() > waferStartData.getCurrent_Qtr_Shipped_Qty()? waferStartData.getM2_fc_qty(): ( waferStartData.getM1_fc_qty() + waferStartData.getM2_fc_qty() ) - waferStartData.getCurrent_Qtr_Shipped_Qty() ) :0 ) +"" : "IF((((" + getAlphaforIdx(columnList.indexOf(currentQtrQty)) + nextRowNumber + "/13)*("+ (getAlphaforIdx(columnList.indexOf(m1Str))+ 2)+"+" + (getAlphaforIdx(columnList.indexOf(m2Str))+ 2)+")))>" + getAlphaforIdx( columnList.indexOf( currentQtrShipments ) )+ nextRowNumber +", IF(((" + getAlphaforIdx(columnList.indexOf(currentQtrQty)) + nextRowNumber + "/13)*" + getAlphaforIdx(columnList.indexOf(m1Str))+ 2+")> " + getAlphaforIdx( columnList.indexOf( currentQtrShipments ) )+ nextRowNumber + ",("+ getAlphaforIdx(columnList.indexOf(currentQtrQty)) + nextRowNumber + "/13)*" + getAlphaforIdx(columnList.indexOf(m2Str))+ 2 +",(((" + getAlphaforIdx(columnList.indexOf(currentQtrQty)) + nextRowNumber + "/13)*("+ (getAlphaforIdx(columnList.indexOf(m1Str))+ 2)+"+" + (getAlphaforIdx(columnList.indexOf(m2Str))+ 2)+")))-" + getAlphaforIdx( columnList.indexOf( currentQtrShipments ) )+ nextRowNumber+"),0)";
	                	formula = "month".equalsIgnoreCase(fctframe)? ( ( waferStartData.getM2_fc_qty()+ waferStartData.getM1_fc_qty() ) > waferStartData.getCurrent_Qtr_Shipped_Qty()? ( waferStartData.getM1_fc_qty() > waferStartData.getCurrent_Qtr_Shipped_Qty()? waferStartData.getM2_fc_qty(): ( waferStartData.getM1_fc_qty() + waferStartData.getM2_fc_qty() ) - waferStartData.getCurrent_Qtr_Shipped_Qty() ) :0 ) +"" :"(((" + getAlphaforIdx(columnList.indexOf(currentQtrQty)) + nextRowNumber  +"-" + getAlphaforIdx( columnList.indexOf( currentQtrShipments ) )+ nextRowNumber + ")/13)*"+ (getAlphaforIdx(columnList.indexOf(m2Str))+ 2 )+")";
	                }*/
	                setCellFormula(row, (short) nextColumnIdx++, formula, productValueStyle);
	
	                if ((waferStartData.getCurrent_Qtr_Backlog() + waferStartData.getCurrent_Qtr_Shipped_Qty()) > waferStartData.getCurrent_Qtr_Forecast()) 
	                {
	                	formula = "month".equalsIgnoreCase(fctframe)? ( ( waferStartData.getM2_fc_qty()+ waferStartData.getM1_fc_qty()+ waferStartData.getM3_fc_qty() ) > waferStartData.getCurrent_Qtr_Shipped_Qty()? ( ( waferStartData.getM1_fc_qty() + waferStartData.getM2_fc_qty()) > waferStartData.getCurrent_Qtr_Shipped_Qty()? waferStartData.getM3_fc_qty(): ( waferStartData.getM1_fc_qty() + waferStartData.getM2_fc_qty() + waferStartData.getM3_fc_qty() ) - waferStartData.getCurrent_Qtr_Shipped_Qty() ) :0 )+"" : "(((" + getAlphaforIdx(columnList.indexOf(currentQtrBacklog)) + nextRowNumber + ")/13)*"+ (getAlphaforIdx(columnList.indexOf(m3Str))+ 2 )+")";
	                }
	                else
	                {
	                	formula = "month".equalsIgnoreCase(fctframe)? ( ( waferStartData.getM2_fc_qty()+ waferStartData.getM1_fc_qty()+ waferStartData.getM3_fc_qty() ) > waferStartData.getCurrent_Qtr_Shipped_Qty()? ( ( waferStartData.getM1_fc_qty() + waferStartData.getM2_fc_qty()) > waferStartData.getCurrent_Qtr_Shipped_Qty()? waferStartData.getM3_fc_qty(): ( waferStartData.getM1_fc_qty() + waferStartData.getM2_fc_qty() + waferStartData.getM3_fc_qty() ) - waferStartData.getCurrent_Qtr_Shipped_Qty() ) :0 )+"" : "(((" + getAlphaforIdx(columnList.indexOf(currentQtrFct)) + nextRowNumber +"-" + getAlphaforIdx( columnList.indexOf( currentQtrShipments ) )+ nextRowNumber + ")/13)*"+ (getAlphaforIdx(columnList.indexOf(m3Str))+ 2 )+")";
	                }
	                
	                if (cycleTimes[2] != 0 && bufferQtyAdded == false) {
	                    
	                    formula += "+" + getAlphaforIdx(columnList.indexOf(bufferQtyStr)) + nextRowNumber;
	                    bufferQtyAdded = true;
	                }/* else {
	                	formula = "month".equalsIgnoreCase(fctframe)? ( ( waferStartData.getM2_fc_qty()+ waferStartData.getM1_fc_qty()+ waferStartData.getM3_fc_qty() ) > waferStartData.getCurrent_Qtr_Shipped_Qty()? ( ( waferStartData.getM1_fc_qty() + waferStartData.getM2_fc_qty()) > waferStartData.getCurrent_Qtr_Shipped_Qty()? waferStartData.getM3_fc_qty(): ( waferStartData.getM1_fc_qty() + waferStartData.getM2_fc_qty() + waferStartData.getM3_fc_qty() ) - waferStartData.getCurrent_Qtr_Shipped_Qty() ) :0 )+"" : "(((" + getAlphaforIdx(columnList.indexOf(currentQtrQty)) + nextRowNumber +"-" + getAlphaforIdx( columnList.indexOf( currentQtrShipments ) )+ nextRowNumber + ")/13)*"+ (getAlphaforIdx(columnList.indexOf(m3Str))+ 2 )+")";
	                }*/
	
	                setCellFormula(row, (short) nextColumnIdx++, formula, productValueStyle);
	
	                if (cycleTimes[3] != 0 && bufferQtyAdded == false) {
	                    formula = "month".equalsIgnoreCase(fctframe)? waferStartData.getM4_fc_qty()+"" : "((" + getAlphaforIdx(columnList.indexOf(nextQtrFct)) + nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m4Str))+ 2 )+")";
	                    formula += "+" + getAlphaforIdx(columnList.indexOf(bufferQtyStr)) + nextRowNumber;
	                    bufferQtyAdded = true;
	                } else {
	                    formula = "month".equalsIgnoreCase(fctframe)? waferStartData.getM4_fc_qty()+"" : "((" + getAlphaforIdx(columnList.indexOf(nextQtrFct)) + nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m4Str))+ 2 )+")";
	                }
	
		            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
		            formula  = "month".equalsIgnoreCase(fctframe)? waferStartData.getM5_fc_qty()+"" : "(("+getAlphaforIdx( columnList.indexOf( nextQtrFct ) )+nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m5Str))+ 2 )+")";
		            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
		            formula  = "month".equalsIgnoreCase(fctframe)? waferStartData.getM6_fc_qty()+"" : "(("+getAlphaforIdx( columnList.indexOf( nextQtrFct ) )+nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m6Str))+ 2 )+")";
		            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
		            formula  = "month".equalsIgnoreCase(fctframe)? waferStartData.getM7_fc_qty()+"" : "(("+getAlphaforIdx( columnList.indexOf( nextNextQtrFct ) )+nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m7Str))+ 2 )+")";
		            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
		            formula  = "month".equalsIgnoreCase(fctframe)? waferStartData.getM8_fc_qty()+"" : "(("+getAlphaforIdx( columnList.indexOf( nextNextQtrFct ) )+nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m8Str))+ 2 )+")";
		            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
		            formula  = "month".equalsIgnoreCase(fctframe)? waferStartData.getM9_fc_qty()+"" : "(("+getAlphaforIdx( columnList.indexOf( nextNextQtrFct ) )+nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m9Str))+ 2 )+")";
		            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
		            formula  = "month".equalsIgnoreCase(fctframe)? waferStartData.getM10_fc_qty()+"" : "(("+getAlphaforIdx( columnList.indexOf( nextNextNextQtrFct ) )+nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m10Str))+ 2 )+")";
		            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
		            formula  = "month".equalsIgnoreCase(fctframe)? waferStartData.getM11_fc_qty()+"" : "(("+getAlphaforIdx( columnList.indexOf( nextNextNextQtrFct ) )+nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m11Str))+ 2 )+")";
		            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
		            formula  = "month".equalsIgnoreCase(fctframe)? waferStartData.getM12_fc_qty()+"" : "(("+getAlphaforIdx( columnList.indexOf( nextNextNextQtrFct ) )+nextRowNumber + "/13)*"+ (getAlphaforIdx(columnList.indexOf(m12Str))+ 2 )+")";
		            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
	            }    
	            
	            formula = "IF("+getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +">"+ getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber
	            			+","+getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber+"-"+ getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber
	            			+",0)";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );

	            formula = "IF( SUM("+getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m2Str ) )+nextRowNumber + ")>"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber
    			+ ",SUM(" +getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m2Str ) )+nextRowNumber + ")-"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber +"-SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber + ")"
    			+",0)";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );

	            formula = "IF( SUM("+getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m3Str ) )+nextRowNumber + ")>"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber
    			+ ",SUM(" +getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m3Str ) )+nextRowNumber + ")-"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber +"-SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( b2Str ) )+nextRowNumber + ")"
    			+",0)";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );

	            formula = "IF( SUM("+getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m4Str ) )+nextRowNumber + ")>"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber
    			+ ",SUM(" +getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m4Str ) )+nextRowNumber + ")-"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber +"-SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( b3Str ) )+nextRowNumber + ")"
    			+",0)";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );

	            formula = "IF( SUM("+getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m5Str ) )+nextRowNumber + ")>"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber
    			+ ",SUM(" +getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m5Str ) )+nextRowNumber + ")-"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber +"-SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( b4Str ) )+nextRowNumber + ")"
    			+",0)";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );

	            formula = "IF( SUM("+getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m6Str ) )+nextRowNumber + ")>"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber
    			+ ",SUM(" +getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m6Str ) )+nextRowNumber + ")-"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber +"-SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( b5Str ) )+nextRowNumber + ")"
    			+",0)";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );

	            formula = "IF( SUM("+getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m7Str ) )+nextRowNumber + ")>"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber
    			+ ",SUM(" +getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m7Str ) )+nextRowNumber + ")-"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber +"-SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( b6Str ) )+nextRowNumber + ")"
    			+",0)";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );

	            formula = "IF( SUM("+getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m8Str ) )+nextRowNumber + ")>"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber
    			+ ",SUM(" +getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m8Str ) )+nextRowNumber + ")-"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber +"-SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( b7Str ) )+nextRowNumber + ")"
    			+",0)";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );

	            formula = "IF( SUM("+getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m9Str ) )+nextRowNumber + ")>"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber
    			+ ",SUM(" +getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m9Str ) )+nextRowNumber + ")-"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber +"-SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( b8Str ) )+nextRowNumber + ")"
    			+",0)";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );

	            formula = "IF( SUM("+getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m10Str ) )+nextRowNumber + ")>"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber
    			+ ",SUM(" +getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m10Str ) )+nextRowNumber + ")-"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber +"-SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( b9Str ) )+nextRowNumber + ")"
    			+",0)";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );

	            formula = "IF( SUM("+getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m11Str ) )+nextRowNumber + ")>"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber
    			+ ",SUM(" +getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m11Str ) )+nextRowNumber + ")-"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber +"-SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( b10Str ) )+nextRowNumber + ")"
    			+",0)";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );

	            formula = "IF( SUM("+getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m12Str ) )+nextRowNumber + ")>"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber
    			+ ",SUM(" +getAlphaforIdx( columnList.indexOf( m1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( m12Str ) )+nextRowNumber + ")-"+getAlphaforIdx( columnList.indexOf( totDieAvailableStr ) )+nextRowNumber +"-SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+nextRowNumber +":"+ getAlphaforIdx( columnList.indexOf( b11Str ) )+nextRowNumber + ")"
    			+",0)";
	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );

	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getFabCycleTime(), productStyle, Cell.CELL_TYPE_NUMERIC  );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getSortCycleTime(), productStyle, Cell.CELL_TYPE_NUMERIC  );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getAssemblyCycleTime(), productStyle, Cell.CELL_TYPE_NUMERIC  );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getTestCycleTime(), productStyle, Cell.CELL_TYPE_NUMERIC  );
	            setCellValue( row, (short)nextColumnIdx++, waferStartData.getEolCycleTime(), productStyle, Cell.CELL_TYPE_NUMERIC  );

	            formula = "SUM(" + getAlphaforIdx( columnList.indexOf( assemblyCycleTime ) )+nextRowNumber + "+"
	            		  + getAlphaforIdx( columnList.indexOf( testCycleTime ) )+nextRowNumber + "+"
	            		  + getAlphaforIdx( columnList.indexOf( eolCycleTime ) )+nextRowNumber+")/7";

	            setCellFormula( row, (short)nextColumnIdx++, formula, productValueStyle );
                
                if( prevAssmPart != null && prevAssmPart.length() > 1 && !prevAssmPart.equalsIgnoreCase( waferStartData.getAssemblyPartNumber() ) )
                {
                    int cycleTime = prevCycleTime;
                    int fullFilledCycleTime = 0;
                    boolean fullFilled = false;
                    int i = 0;
                    formula = "";
                    while ( !fullFilled ) 
                    {
                        fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];
                        if( fullFilledCycleTime >= cycleTime ) {
                            fullFilled = true;
                        } else {
                            i++;
                        }
                    }
                    
                    formula = "(SUM("+getCellReference( columnList.indexOf( b1Str ), mergerIdx)+":";
                    if ( fullFilledCycleTime > cycleTime && i > 0 )
                    {
                        formula = formula + getCellReference(columnList.indexOf( monthArray[i - 1] ),mergerIdx)+") + (("
                                    + getCellReference( columnList.indexOf( monthArray[i] ), mergerIdx) + "/"
                                    + getCellReference( columnList.indexOf( monthArray[i] ) ,2) +")*"
                                    + ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))";
                    } 
                    else 
                    {
                        formula = formula + getCellReference( columnList.indexOf( monthArray[i] ), mergerIdx)+"))";
                    }

                    //System.out.println("FORMULA:::::" + formula);
                    if( cycleTimes[0] == 0 ) 
                    {
                        setCellValue( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, 0, productValueStyle, Cell.CELL_TYPE_NUMERIC );
                    } 
                    else 
                    {
                        setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                    }
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w1Str), nextRowNumber- 2, (short)columnList.indexOf(w1Str) );

                    //P2STR
                    formula = "((SUM("+getCellReference( columnList.indexOf( b1Str ), mergerIdx)+":";
                    cycleTime = cycleTime + cycleTimes[1];
                    fullFilledCycleTime = 0;
                    fullFilled = false;
                    i = 0;
                    
                    while ( !fullFilled )
                    {
                        fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];
                        if( fullFilledCycleTime >= cycleTime )
                        {
                            fullFilled = true;
                        }
                        else
                        {
                            i++;
                        }
                    }

                    if ( fullFilledCycleTime > cycleTime  && i > 1 )
                    {
                        formula = formula + getCellReference( columnList.indexOf( monthArray[i - 1] ), mergerIdx)+") + (("
                                    + getCellReference( columnList.indexOf( monthArray[i] ), mergerIdx) + "/"
                                    + getCellReference( columnList.indexOf( monthArray[i] ), 2) +")*"
                                    + ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))"
                                    +")-SUM("
                                    + getCellReference( columnList.indexOf( w1Str ), mergerIdx)+":"
                                    + getCellReference( columnList.indexOf( w1Str ), mergerIdx)+")";
                    }
                    else
                    {
                        formula = formula + getCellReference( columnList.indexOf( monthArray[i] ), mergerIdx)+"))"
                                     + ")-SUM("
                                    + getCellReference( columnList.indexOf( w1Str ), mergerIdx)+":"
                                    + getCellReference( columnList.indexOf( w1Str ), mergerIdx)+")";
                        
                    }
                    if( cycleTimes[1] == 0 ) {
                        setCellValue( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, 0, productValueStyle, Cell.CELL_TYPE_NUMERIC );
                    } else {
                        setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                    }
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w2Str), nextRowNumber- 2, (short)columnList.indexOf(w2Str) );
                    
                    //P3STR
                    formula = "((SUM("+getCellReference( columnList.indexOf( b1Str ), mergerIdx)+":";
                    cycleTime = cycleTime + cycleTimes[2];
                    fullFilledCycleTime = 0;
                    fullFilled = false;
                    i = 0;
                    while ( !fullFilled )
                    {
                        fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];
                        if( fullFilledCycleTime >= cycleTime )
                        {
                            fullFilled = true;
                        }
                        else
                        {
                            i++;
                        }
                    }

                    if ( fullFilledCycleTime > cycleTime && i > 2 )
                    {
                        formula = formula + getCellReference( columnList.indexOf( monthArray[i - 1] ), mergerIdx)+") + (("
                                    + getCellReference( columnList.indexOf( monthArray[i] ), mergerIdx) + "/"
                                    + getCellReference( columnList.indexOf( monthArray[i] ), 2) +")*"
                                    + ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))"
                                    +")-SUM("
                                    + getCellReference( columnList.indexOf( w1Str ), mergerIdx)+":"
                                    + getCellReference( columnList.indexOf( w2Str ), mergerIdx)+")";
                    }
                    else
                    {
                        formula = formula + getCellReference( columnList.indexOf( monthArray[i] ), mergerIdx)+"))"
                                     + ")-SUM("
                                    + getCellReference( columnList.indexOf( w1Str ), mergerIdx)+":"
                                    + getCellReference( columnList.indexOf( w2Str ), mergerIdx)+")";
                    }

                    if( cycleTimes[2] == 0 )
                    {
                        setCellValue( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, 0, productValueStyle, Cell.CELL_TYPE_NUMERIC );
                    }
                    else
                    {
                        setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                    }
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w3Str), nextRowNumber- 2, (short)columnList.indexOf(w3Str) );
                    
                    //P4STR
                    formula = "((SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+mergerIdx+":";
                    cycleTime = cycleTime + cycleTimes[3];
                    fullFilledCycleTime = 0;
                    fullFilled = false;
                    i = 0;
                    while ( !fullFilled )
                    {
                        fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];
                        if( fullFilledCycleTime >= cycleTime )
                        {
                            fullFilled = true;
                        }
                        else
                        {
                            i++;
                        }
                    }

                    if ( fullFilledCycleTime > cycleTime  && i > 3  )
                    {
                        formula = formula + getCellReference( columnList.indexOf( monthArray[i - 1] ), mergerIdx)+") + (("
                                    + getCellReference( columnList.indexOf( monthArray[i] ), mergerIdx) + "/"
                                    + getCellReference( columnList.indexOf( monthArray[i] ), 2) +")*"
                                    + ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))"
                                    +")-SUM("
                                    + getCellReference( columnList.indexOf( w1Str ), mergerIdx)+":"
                                    + getCellReference( columnList.indexOf( w3Str ), mergerIdx)+")";
                    }
                    else
                    {
                        formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx+"))"
                                     + ")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( w3Str ) )+mergerIdx+")";
                    }
                    
                    setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w4Str), nextRowNumber- 2, (short)columnList.indexOf(w4Str) );
                    
                    //P5STR
                    formula = "((SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+mergerIdx+":";
                    cycleTime = cycleTime + cycleTimes[4];
                    fullFilledCycleTime = 0;
                    fullFilled = false;
                    i = 0;
                    while ( !fullFilled )
                    {
                        fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];
                        if( fullFilledCycleTime >= cycleTime )
                        {
                            fullFilled = true;
                        }
                        else
                        {
                            i++;
                        }
                    }

                    if ( fullFilledCycleTime > cycleTime && i > 4 )
                    {
                        formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i - 1] ) )+mergerIdx+") + (("
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx + "/"
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+2 +")*"
                                    + ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))"
                                    +")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( w4Str ) )+mergerIdx+")";
                    }
                    else
                    {
                        formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx+"))"
                                     + ")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( w4Str ) )+mergerIdx+")";
                    }
                    setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w5Str), nextRowNumber- 2, (short)columnList.indexOf(w5Str) );

                    //P6STR
                    formula = "((SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+mergerIdx+":";
                    cycleTime = cycleTime + cycleTimes[5];
                    fullFilledCycleTime = 0;
                    fullFilled = false;
                    i = 0;
                    while ( !fullFilled && i < 12 )
                    {
                        fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];

                        if( fullFilledCycleTime >= cycleTime )
                        {
                            fullFilled = true;
                        }
                        else
                        {
                            i++;
                        }
                    }

                    if ( fullFilledCycleTime > cycleTime && i > 5 )
                    {
                        formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i - 1] ) )+mergerIdx+") + (("
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx + "/"
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+2 +")*"
                                    + ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))"
                                    +")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( w5Str ) )+mergerIdx+")";
                    }
                    else
                    {
                        if ( i < 12 )
                        {
                            formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx+"))"
                                     + ")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( w5Str ) )+mergerIdx+")";
                        }
                        else
                        {
                            formula = "";
                        }
                    }
                    if ( formula.length() > 1 )
                    {
                        setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                        mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w6Str), nextRowNumber- 2, (short)columnList.indexOf(w6Str) );
                    }
                    else
                    {
                        setCellValue( row, (short)nextColumnIdx++, 0, productStyle, Cell.CELL_TYPE_NUMERIC  );
                        mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w6Str), nextRowNumber- 2, (short)columnList.indexOf(w6Str) );
                    }

                    //P7STR
                    formula = "((SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+mergerIdx+":";
                    cycleTime = cycleTime + cycleTimes[6];
                    fullFilledCycleTime = 0;
                    fullFilled = false;
                    i = 0;
                    while ( !fullFilled && i < 12 )
                    {
                        fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];

                        if( fullFilledCycleTime >= cycleTime )
                        {
                            fullFilled = true;
                        }
                        else
                        {
                            i++;
                        }
                    }

                    if ( fullFilledCycleTime > cycleTime && i > 6 )
                    {
                        formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i - 1] ) )+mergerIdx+") + (("
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx + "/"
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+2 +")*"
                                    + ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))"
                                    +")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( w6Str ) )+mergerIdx+")";
                    }
                    else
                    {
                        if ( i < 12 )
                        {
                            formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx+"))"
                                     + ")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( w6Str ) )+mergerIdx+")";
                        }
                        else
                        {
                            formula = "";
                        }
                    }
                    if ( formula.length() > 1 )
                    {
                        setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                        mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w7Str), nextRowNumber- 2, (short)columnList.indexOf(w7Str) );
                    }
                    else
                    {
                        setCellValue( row, (short)nextColumnIdx++, 0, productStyle, Cell.CELL_TYPE_NUMERIC  );
                        mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w7Str), nextRowNumber- 2, (short)columnList.indexOf(w7Str) );
                    }

                    //P8STR
                    formula = "((SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+mergerIdx+":";
                    cycleTime = cycleTime + cycleTimes[7];
                    fullFilledCycleTime = 0;
                    fullFilled = false;
                    i = 0;
                    while ( !fullFilled && i < 12 )
                    {
                        fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];
                        if( fullFilledCycleTime >= cycleTime )
                        {
                            fullFilled = true;
                        }
                        else
                        {
                            i++;
                        }
                    }

                    if ( fullFilledCycleTime > cycleTime && i > 7 )
                    {

                        formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i - 1] ) )+mergerIdx+") + (("
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx + "/"
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+2 +")*"
                                    + ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))"
                                    +")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( w7Str ) )+mergerIdx+")";
                    }
                    else
                    {
                        if( i < 12 )// Need to remove later...........
                        {

                            formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx+"))"
                                     + ")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( w7Str ) )+mergerIdx+")";
                        }
                        else
                        {
                            formula = "";
                        }
                    }

                    if( formula.length() > 1 )
                    {
                        setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                        mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w8Str), nextRowNumber- 2, (short)columnList.indexOf(w8Str) );
                    }
                    else
                    {
                        setCellValue( row, (short)nextColumnIdx++, 0, productStyle, Cell.CELL_TYPE_NUMERIC  );
                        mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w8Str), nextRowNumber- 2, (short)columnList.indexOf(w8Str) );
                    }

                    //W8STR
                    formula = "((SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+mergerIdx+":";
                    cycleTime = cycleTime + cycleTimes[8];
                    fullFilledCycleTime = 0;
                    fullFilled = false;
                    i = 0;
                    while ( !fullFilled && i < 12 )
                    {
                        fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];
                        if( fullFilledCycleTime >= cycleTime )
                        {
                            fullFilled = true;
                        }
                        else
                        {
                            i++;
                        }
                    }

                    if( i == 12 ) i = 11;

                    if ( fullFilledCycleTime > cycleTime && i > 7 )
                    {
                        formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i - 1] ) )+mergerIdx+") + (("
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx + "/"
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+2 +")*"
                                    + ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))"
                                    +")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( w8Str ) )+mergerIdx+")";
                    }
                    else
                    {
                        formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx+"))"
                                    + ")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( w8Str ) )+mergerIdx+")";
                        /*}
                        else
                        {
                            formula = "";
                        }*/
                    }
                    if( formula.length() > 1 )
                    {
                        setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                        mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w9Str), nextRowNumber- 2, (short)columnList.indexOf(w9Str) );
                    }
                    else
                    {
                       setCellValue( row, (short)nextColumnIdx++, 0, productStyle, Cell.CELL_TYPE_NUMERIC  );
                        mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w9Str), nextRowNumber- 2, (short)columnList.indexOf(w9Str) );
                    }


                    //W9STR
                    formula = "((SUM("+getAlphaforIdx( columnList.indexOf( b1Str ) )+mergerIdx+":";
                    cycleTime = cycleTime + cycleTimes[9];
                    fullFilledCycleTime = 0;
                    fullFilled = false;
                    i = 0;
                    while ( !fullFilled && i < 12 )
                    {
                        fullFilledCycleTime = fullFilledCycleTime + cycleTimes[i];
                        if( fullFilledCycleTime >= cycleTime )
                        {
                            fullFilled = true;
                        }
                        else
                        {
                            i++;
                        }
                    }

                    if( i == 12 ) i = 11;

                    if ( fullFilledCycleTime > cycleTime && i > 9 )
                    {
                        formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i - 1] ) )+mergerIdx+") + (("
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx + "/"
                                    + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+2 +")*"
                                    + ( cycleTimes[i]+ cycleTime - fullFilledCycleTime )+ "))"
                                    +")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( w9Str ) )+mergerIdx+")";
                    }
                    else
                    {
                        //if ( i < 12 )
                        //{
                            formula = formula + getAlphaforIdx( columnList.indexOf( monthArray[i] ) )+mergerIdx+"))"
                                     + ")-SUM("
                                    + getAlphaforIdx( columnList.indexOf( w1Str ) )+mergerIdx+":"
                                    + getAlphaforIdx( columnList.indexOf( w9Str ) )+mergerIdx+")";
                        /*}
                        else
                        {
                            formula = "";
                        } */
                    }
                    if (formula.length() > 1 )
                    {
                        setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, formula, productValueStyle );
                        mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w10Str), nextRowNumber- 2, (short)columnList.indexOf(w10Str) );
                    }
                    else
                    {
                        setCellValue( row, (short)nextColumnIdx++, 0, productStyle, Cell.CELL_TYPE_NUMERIC  );
                        mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w10Str), nextRowNumber- 2, (short)columnList.indexOf(w10Str) );
                    }

                    setCellValue( row, (short)nextColumnIdx++, 0, productStyle, Cell.CELL_TYPE_NUMERIC  );
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w11Str), nextRowNumber- 2, (short)columnList.indexOf(w11Str) );

                    setCellValue( row, (short)nextColumnIdx++, 0, productStyle, Cell.CELL_TYPE_NUMERIC  );
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(w12Str), nextRowNumber- 2, (short)columnList.indexOf(w12Str) );

                    // ww1
                    if( cycleTimes[0] > 3 ) 
                    {
                    	setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, getCellReference( columnList.indexOf( w1Str ), mergerIdx)+"/"+ cycleTimes[0], productValueStyle );
                    } 
                    else 
                    {
                    	setCellValue( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, 0, productValueStyle, Cell.CELL_TYPE_NUMERIC );
                    }
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(ww1Str), nextRowNumber- 2, (short)columnList.indexOf(ww1Str) );
                    
                    // ww2
                    if( cycleTimes[0] > 2 ) 
                    {
                    	setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, getCellReference( columnList.indexOf( w1Str ), mergerIdx)+"/"+ cycleTimes[0], productValueStyle );
                    } 
                    else 
                    {
                    	setCellValue( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, 0, productValueStyle, Cell.CELL_TYPE_NUMERIC );
                    }
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(ww2Str), nextRowNumber- 2, (short)columnList.indexOf(ww2Str) );

                    // ww3
                    if( cycleTimes[0] > 1 ) 
                    {
                    	setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, getCellReference( columnList.indexOf( w1Str ), mergerIdx)+"/"+ cycleTimes[0], productValueStyle );
                    } 
                    else 
                    {
                    	setCellValue( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, 0, productValueStyle, Cell.CELL_TYPE_NUMERIC );
                    }
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(ww3Str), nextRowNumber- 2, (short)columnList.indexOf(ww3Str) );
                    
                    // ww4
                    if( cycleTimes[0] > 0 ) 
                    {
                    	setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, getCellReference( columnList.indexOf( w1Str ), mergerIdx)+"/"+ cycleTimes[0], productValueStyle );
                    } 
                    else 
                    {
                    	setCellValue( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, 0, productValueStyle, Cell.CELL_TYPE_NUMERIC );
                    }
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(ww4Str), nextRowNumber- 2, (short)columnList.indexOf(ww4Str) );
                    
                    // ww5
                    if( cycleTimes[1] > 3 ) 
                    {
                    	setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, getCellReference( columnList.indexOf( w2Str ), mergerIdx)+"/"+ cycleTimes[1], productValueStyle );
                    } 
                    else 
                    {
                    	setCellValue( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, 0, productValueStyle, Cell.CELL_TYPE_NUMERIC );
                    }
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(ww5Str), nextRowNumber- 2, (short)columnList.indexOf(ww5Str) );
                    
                    // ww6
                    if( cycleTimes[1] > 2 ) 
                    {
                    	setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, getCellReference( columnList.indexOf( w2Str ), mergerIdx)+"/"+ cycleTimes[1], productValueStyle );
                    } 
                    else 
                    {
                    	setCellValue( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, 0, productValueStyle, Cell.CELL_TYPE_NUMERIC );
                    }
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(ww6Str), nextRowNumber- 2, (short)columnList.indexOf(ww6Str) );

                    // ww7
                    if( cycleTimes[1] > 1 ) 
                    {
                    	setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, getCellReference( columnList.indexOf( w2Str ), mergerIdx)+"/"+ cycleTimes[1], productValueStyle );
                    } 
                    else 
                    {
                    	setCellValue( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, 0, productValueStyle, Cell.CELL_TYPE_NUMERIC );
                    }
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(ww7Str), nextRowNumber- 2, (short)columnList.indexOf(ww7Str) );
                    
                    // ww8
                    if( cycleTimes[1] > 0 ) 
                    {
                    	setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, getCellReference( columnList.indexOf( w2Str ), mergerIdx)+"/"+ cycleTimes[1], productValueStyle );
                    } 
                    else 
                    {
                    	setCellValue( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, 0, productValueStyle, Cell.CELL_TYPE_NUMERIC );
                    }
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(ww8Str), nextRowNumber- 2, (short)columnList.indexOf(ww8Str) );
                    
                    // ww9
                    if( cycleTimes[2] > 4 ) 
                    {
                    	setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, getCellReference( columnList.indexOf( w3Str ), mergerIdx)+"/"+ cycleTimes[2], productValueStyle );
                    } 
                    else 
                    {
                    	setCellValue( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, 0, productValueStyle, Cell.CELL_TYPE_NUMERIC );
                    }
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(ww9Str), nextRowNumber- 2, (short)columnList.indexOf(ww9Str) );
                    
                    // ww10
                    if( cycleTimes[2] > 3 ) 
                    {
                    	setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, getCellReference( columnList.indexOf( w3Str ), mergerIdx)+"/"+ cycleTimes[2], productValueStyle );
                    } 
                    else 
                    {
                    	setCellValue( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, 0, productValueStyle, Cell.CELL_TYPE_NUMERIC );
                    }
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(ww10Str), nextRowNumber- 2, (short)columnList.indexOf(ww10Str) );

                    // ww11
                    if( cycleTimes[2] > 2 ) 
                    {
                    	setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, getCellReference( columnList.indexOf( w3Str ), mergerIdx)+"/"+ cycleTimes[2], productValueStyle );
                    } 
                    else 
                    {
                    	setCellValue( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, 0, productValueStyle, Cell.CELL_TYPE_NUMERIC );
                    }
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(ww11Str), nextRowNumber- 2, (short)columnList.indexOf(ww11Str) );
                    
                    // ww12
                    if( cycleTimes[2] > 1 ) 
                    {
                    	setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, getCellReference( columnList.indexOf( w3Str ), mergerIdx)+"/"+ cycleTimes[2], productValueStyle );
                    } 
                    else 
                    {
                    	setCellValue( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, 0, productValueStyle, Cell.CELL_TYPE_NUMERIC );
                    }
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(ww12Str), nextRowNumber- 2, (short)columnList.indexOf(ww12Str) );

                    // ww13
                    if( cycleTimes[2] > 0 ) 
                    {
                    	setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, getCellReference( columnList.indexOf( w3Str ), mergerIdx)+"/"+ cycleTimes[2], productValueStyle );
                    } 
                    else 
                    {
                    	setCellValue( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, 0, productValueStyle, Cell.CELL_TYPE_NUMERIC );
                    }
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(ww13Str), nextRowNumber- 2, (short)columnList.indexOf(ww13Str) );
                    // ww14
                    if( cycleTimes[3] > 3 ) 
                    {
                    	setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, getCellReference( columnList.indexOf( w4Str ), mergerIdx)+"/"+ cycleTimes[3], productValueStyle );
                    } 
                    else 
                    {
                    	setCellValue( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, 0, productValueStyle, Cell.CELL_TYPE_NUMERIC );
                    }
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(ww14Str), nextRowNumber- 2, (short)columnList.indexOf(ww14Str) );
                    
                    // ww15
                    if( cycleTimes[3] > 2 ) 
                    {
                    	setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, getCellReference( columnList.indexOf( w4Str ), mergerIdx)+"/"+ cycleTimes[3], productValueStyle );
                    } 
                    else 
                    {
                    	setCellValue( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, 0, productValueStyle, Cell.CELL_TYPE_NUMERIC );
                    }
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(ww15Str), nextRowNumber- 2, (short)columnList.indexOf(ww15Str) );

                    // ww16
                    if( cycleTimes[3] > 1 ) 
                    {
                    	setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, getCellReference( columnList.indexOf( w4Str ), mergerIdx)+"/"+ cycleTimes[3], productValueStyle );
                    } 
                    else 
                    {
                    	setCellValue( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, 0, productValueStyle, Cell.CELL_TYPE_NUMERIC );
                    }
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(ww16Str), nextRowNumber- 2, (short)columnList.indexOf(ww16Str) );
                    
                    // ww17
                    if( cycleTimes[3] > 0 ) 
                    {
                    	setCellFormula( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, getCellReference( columnList.indexOf( w4Str ), mergerIdx)+"/"+ cycleTimes[3], productValueStyle );
                    } 
                    else 
                    {
                    	setCellValue( sheet.getRow( mergerIdx-1 ), (short)nextColumnIdx++, 0, productValueStyle, Cell.CELL_TYPE_NUMERIC );
                    }
                    mergeCells(sheet, mergerIdx-1, (short)columnList.indexOf(ww17Str), nextRowNumber- 2, (short)columnList.indexOf(ww17Str) );


                    
                    mergerIdx = nextRowNumber;
                }

                prevAssmPart = waferStartData.getAssemblyPartNumber();
                prevCycleTime = (waferStartData.getAssemblyCycleTime() + waferStartData.getTestCycleTime() + waferStartData.getEolCycleTime())/7;

                //--------------------------------

            } 
        }
        catch(Exception e)
        {
        	e.printStackTrace();
        }
        return workbook;
    }
    
    /**
     * merges cells and sets each cell with the given cellStyle.
     * @param sheet
     * sheet object in which the cells has to be merged.
     * @param startRow
     * start row Number to merge from.<br>
     * starts from 0.
     * @param startCell
     * start cell number in the start row to merge from.<br>
     * starts from 0.
     * @param endRow
     * end row Number<br>
     * starts from 0.
     * @param endCell
     * end cell number<br>
     * starts from 0.
     * @param endCell
     * @return
     * returns cell object of the startRow, startCell.
     */
    private static Cell mergeCells ( Sheet sheet, int startRow, short startCell, int endRow, short endCell, CellStyle cellStyle )
    {
        sheet.addMergedRegion( new CellRangeAddress( startRow, endRow, startCell,endCell ) );
        Cell cell = null;
        for ( int rowIdx = startRow; rowIdx <= endRow; rowIdx++ )
        {
            for ( int cellIdx = startCell; cellIdx <= endCell; cellIdx++ )
            {
                cell = getCellAt( sheet.getRow ( rowIdx ), (short)cellIdx );
                cell.setCellStyle ( cellStyle );
            }
        }
        return getCellAt( sheet.getRow( startRow), startCell );
    }
    
    private Cell mergeCells ( Sheet sheet, int startRow, int startCell, int endRow, int endCell )
    {
        //creating rows if not created
        for ( int rowIdx = startRow; rowIdx <= endRow; rowIdx++ )
        {
            if ( sheet.getRow( rowIdx) == null )
            {
                sheet.createRow( rowIdx );
            }
        }
        sheet.addMergedRegion( new CellRangeAddress( startRow, endRow, startCell, endCell ) );
        Cell startCellObj = getCellAt( sheet.getRow( startRow), startCell );
        Cell cell = null;
        for ( int rowIdx = startRow; rowIdx <= endRow; rowIdx++ )
        {
            for ( int cellIdx = startCell; cellIdx <= endCell; cellIdx++ )
            {
                cell = getCellAt( sheet.getRow ( rowIdx ), (short)cellIdx );
                cell.setCellStyle ( startCellObj.getCellStyle() );
            }
        }
        if ( mergeIdxMap.containsKey( startCell + "" ) )
        {
            ArrayList<Range> rangeList = (ArrayList<Range>)mergeIdxMap.get(startCell+"");
            rangeList.add( new Range((startRow+1),(endRow+1)) );
        }
        else
        {
            ArrayList<Range> rangeList = new ArrayList<Range>();
            rangeList.add ( new Range((startRow+1),(endRow+1)) );
            mergeIdxMap.put( startCell+"", rangeList );
        }
        return startCellObj;//getCellAt( sheet.getRow( startRow), startCell );
    }
    /**
     * Returns the cell object at the specified cell in the row.<br>
     * It creats cell if doesn't exists.
     * @param row
     * row object from which cell object has to be picked
     * @param cellNumber
     * starts from 0.
     * @return
     */
    private static Cell getCellAt ( Row row, int cellNumber )
    {
        Cell cell = null;
        cell = row.getCell( cellNumber );
        if ( cell == null )
        {
            cell = row.createCell ( cellNumber );
        }
        return cell;
    }
    private static void setCellValue ( Cell cell, RichTextString value, CellStyle cellStyle )
    {
        if ( cellStyle != null )
        {
            cell.setCellStyle( cellStyle );
        }
        cell.setCellValue( value );
    }
    private static void setCellValue ( Row row, int cellNo, RichTextString value, CellStyle cellStyle )
    {
        Cell cell   = row.createCell( cellNo );
        if ( cellStyle != null )
        {
            cell.setCellStyle( cellStyle);
        }
        cell.setCellValue(value);
    }
    
    private static void setCellValue ( Row row, int cellNo, int value, CellStyle cellStyle, int cellType )
    {
        Cell cell   = row.createCell( cellNo );
        if ( cellStyle != null )
        {
            cell.setCellStyle( cellStyle);
        }
        cell.setCellValue( value );
        cell.setCellType( cellType );
    }
    private static void setCellValue ( Row row, int cellNo, double value, CellStyle cellStyle, int cellType )
    {
        Cell cell   = row.createCell( cellNo );
        if ( cellStyle != null )
        {
            cell.setCellStyle( cellStyle);
        }
        cell.setCellValue( value );
        cell.setCellType( cellType );
    }
     private static void setCellFormula ( Row row, int cellNo, String formula, CellStyle cellStyle )
    {
        Cell cell   = row.createCell( cellNo );
        if ( cellStyle != null )
        {
            cell.setCellStyle( cellStyle);
        }
        cell.setCellFormula( formula );
        //evaluator.evaluateInCell (cell); 
    }

    /**
     *
     * @param idx - zero based index
     *
     * @return
     */
    private static String getAlphaforIdx ( int idx )
    {
        String[] alpha = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
        String formatted = "";
        if ( idx < alpha.length )
        {
            formatted = alpha[idx];
        }
        else
        {
            //idx=idx+1;
            int idx1 = (idx/26)-1;
            int idx2 = (idx)%26;
            if ( idx1 >= 0 )
            {
                formatted = alpha[idx1];
            }
            if ( idx2 >= 0 )
            {
                formatted = formatted+alpha[idx2];
            }
        }
        return formatted;
    }
    
    private String getCellReference ( int columnIdx, int rowNumber )
    {
        return getAlphaforIdx( columnIdx ) + getValueRowNumber(columnIdx,rowNumber);
    }
    
    private int getValueRowNumber ( int columnIdx, int rowNumber )
    {
        ArrayList<Range> rangeList = (ArrayList<Range>)mergeIdxMap.get( columnIdx+"" );
        if ( rangeList == null )
        {
            return rowNumber;
        }
        else
        {
            for ( int i=0; i < rangeList.size(); i++ )
            {
                Range range = (Range)rangeList.get(i);
                if ( range.contains(rowNumber) )
                {
                    return range.fromRowNumber;
                }
            }
        }
        return rowNumber;
    }
    class  Range
    {
        int fromRowNumber; //starts from 1
        int toRowNumber; //starts from 1

        public Range(int fromRowNumber, int toRowNumber) {
            this.fromRowNumber = fromRowNumber;
            this.toRowNumber = toRowNumber;
        }
        public boolean contains( int rowNumber )
        {
            return ( rowNumber >= fromRowNumber && rowNumber <= toRowNumber );
        }
    }
}
